对于每个细胞我都有特定的课程
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表示不可能同时使用这两个功能。我需要做什么?
答案 0 :(得分:0)
通过查看注释,我假设您需要备用行类型。
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
}
}