简短的答案:节省资源。textLabel属性是可选的,以允许对UILabel进行延迟初始化。换句话说,该属性保持为零,除非您实际尝试访问它。
您可以在调试器中通过检查UITableViewCell的实例来验证这一点:
let cell = dequeueReusableCellWithIdentifier(MyCell.cellIdentifier, forIndexPath: indexPath) as! MyCell
// check cell.textLabel here in the debugger. should be nil.
cell.textLabel.text = "test" // creates textLabel via lazy initialization
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句