gpt4 book ai didi

ios - UITableViewCell 初始化失败 (Swift)

转载 作者:行者123 更新时间:2023-11-30 11:20:09 25 4
gpt4 key购买 nike

我正在使用 tableView并尝试创建我的 cells ..徒劳。我设置了我们必须做的所有事情(创建了一个原型(prototype)单元,给出了一个标识符(“CustomerCell”),在 delegatedataSource 中设置了 storyBoardViewDidLoad,设置了良好的类在 StoryBoard 中为 tableViewcells 等)。

这是我的代码:

override func viewDidLoad() {

self.tableView.delegate = self
self.tableView.dataSource = self
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let item = items[indexPath.section]
switch item.type {

case .customer:

if let cell = tableView.dequeueReusableCell(withIdentifier: "CustomerCell", for: indexPath) as? CustomerCellSetter {
cell.item = item as? Customer // THIS is never called, the cell return nil all the time
return cell
}

return UITableViewCell()
}

cell ID

Delegates

方程式中是否还有其他参数可以获取我的细胞?预先感谢您的宝贵帮助!

编辑:

这是我的UITableViewCell类(class):

class CustomerCellSetter: CustomerTableViewCell {
var item: Customer? {
didSet {
guard let item = item else {
return }
if let firstName = item.firstName {
fisrtName?.text = firstName
}

if let theLastName = item.lastName {
lastName.text = theLastName
}

if let theGsm = item.GSM {
gsm.text = theGsm
}

if let theMail = item.mail {
mail.text = theMail
}

if let theAdress = item.adress {
adress.text = theAdress
}

if let theNote = item.notes {
notes.text = theNote
}

}
}

}




class CustomerTableViewCell: UITableViewCell {


@IBOutlet var fisrtName : UILabel!
@IBOutlet var lastName : UILabel!
@IBOutlet var gsm : UILabel!
@IBOutlet var mail : UILabel!
@IBOutlet var adress : UILabel!
@IBOutlet var notes : UILabel!




override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

}

编辑2:

enter image description here

最佳答案

您是否将单元格的类设置为“CustomerCellSetter”?

这可以在身份检查器中完成。

关于ios - UITableViewCell 初始化失败 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51348160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com