我有一个包含一个静态部分的静态表。其他部分是动态的。
我为动态部分创建表格部分和表格单元格。为 Cell 设置标识符,为其设置自定义类,甚至可以执行以下操作:
self.tableView.registerClass(UncheckedStoreTableViewCell.self, forCellReuseIdentifier: "StoreCell")
如果我不使用代码注册它,那么我会得到:
'unable to dequeue a cell with identifier StoreCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
所以当我使用它时:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0 {
return super.tableView(tableView, cellForRowAtIndexPath: indexPath)
}
let cell = tableView.dequeueReusableCellWithIdentifier("StoreCell", forIndexPath: indexPath) as! UncheckedStoreTableViewCell
return cell
}
它有效。但是如果我想改变标签:cell.myLabel.text = "one"
或者只是 print(cell.myLabel) 得到
BAD_INSTRUCTION
最佳答案
顺便说一句,如果您已经为您的单元格定义了一个自定义的 .nib,则有这个方法:registerNib(_:forCellReuseIdentifier:)
关于ios - dequeueReusableCellWithIdentifier 不返回单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35607397/