有人知道如何填写2个不同的单元格吗? 如何填写2个不同的单元格?
对于每一个细胞我有特定的类
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个这些功能时间。我需要做什么?
您如何知道要使用哪个单元格?不同的tableView或相同?只是在相同和独特的'func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) - > UITableViewCell',do和'if'测试那里使用一个或另一个。 – Larme
每个单元都有自己的标识符 –
的确,但它们有一个顺序,一个indexPath。显示“MindCell”时以及显示“StepsMind”时的逻辑是什么? – Larme