对于每个单元格,我都有特定的类别
import UIKit
class MindCell: UITableViewCell {
@IBOutlet var textLabel1: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
class StepsMind: UITableViewCell {
@IBOutlet var number1Label: UILabel!
@IBOutlet var step1Label: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
但我不知道如何设置功能
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MindCell
// Configure the cell...
cell.textLabel1.text = "ABC"
return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier1 = "MindCell"
let cell1 = tableView.dequeueReusableCell(withIdentifier: cellIdentifier1, for: indexPath) as! StepsMind
// Configure the cell...
cell1.number1Label.text = "1"
cell1.step1Label.text = "DEF"
return cell1
}
Xcode 表示不可能同时使用 2 个这些功能。我需要做什么?
最佳答案
通过查看评论,我假设您需要备用行类型。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if indexPath.row % 2 == 0
{
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MindCell
// Configure the cell...
cell.textLabel1.text = "ABC"
return cell
}
else
{
let cellIdentifier1 = "MindCell"
let cell1 = tableView.dequeueReusableCell(withIdentifier: cellIdentifier1, for: indexPath) as! StepsMind
// Configure the cell...
cell1.number1Label.text = "1"
cell1.step1Label.text = "DEF"
return cell1
}
}
关于ios - 如何填写2个不同的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42368672/