Reference from UITableViewCell to parent UITableView?

前端 未结 7 1731
有刺的猬
有刺的猬 2020-11-29 04:02

Is there any way to access the owning UITableView from within a UITableViewCell?

7条回答
  •  长情又很酷
    2020-11-29 04:47

    Store a weak reference to the tableView in the cell, which you'd set in -tableView:cellForRowAtIndexPath: of your table's dataSource.

    This is better than relying on self.superview to always be exactly the tableView is fragile. Who knows how Apple might re-organize the view hierarchy of UITableView in the future.

提交回复
热议问题