Tom*_*you 6 uitableview ios swift
我需要能够检测我的自定义何时UITableViewCell被加载到屏幕上,以便我可以以编程方式对其中的视图执行操作.我可以使用的唯一代码是layoutSubviews()在自定义内部实现UITableViewCell,但这是不好的做法,因为layoutSubviews()被调用了不止一次.另外,放入我的代码awakeFromNib()不起作用,因为我需要调用一个委托属性,该属性尚未设置.我怎样才能做到这一点?
Cra*_*ens 12
有两种不同的方法可以做到.
在您的工作中,UITableViewDelegate您可以实现在即将显示单元格时调用的委托方法.
func tableView(_ tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// Update the cell
}
Run Code Online (Sandbox Code Playgroud)
或者在您的UITableViewCell子类中,您可以实现didMoveToSuperView.
override func didMoveToSuperview() {
super.didMoveToSuperview()
if superview != nil {
// Update the cell
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8541 次 |
| 最近记录: |