我有一个自定义的 UITableViewCell 子类,其中为 UILabel 设置了一个简单的 IBOutlet。
class SegmentCell: UITableViewCell {
@IBOutlet weak var test: UILabel!
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
test.text = "Some Text"
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
确信我已经按照其他答案正确设置了所有内容,但 UILabel 始终为零。
View Controller : 查看加载:
self.tableView.registerClass(SegmentCell.self, forCellReuseIdentifier: "Cell")
cellForForAtIndexPath
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! SegmentCell
return cell
}
- 单元格设置为自定义
- 重用标识符正确
- Cells 类是 SegmentCell
- Tableview 内容是动态原型(prototype)
我错过了什么?
最佳答案
因为你是 uisg Xib 文件,你必须注册,
tableView.register(UINib(nibName: "yourNib", bundle: nil), forCellReuseIdentifier: "CellFromNib")
想一想,如果只注册类,系统将不知道它的 Xib。这对我有用。
关于ios - 自定义 UITableviewCell IBOutlet 始终为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33287927/