从 UITableViewCell 到父 UITableView 的引用? [英] Reference from UITableViewCell to parent UITableView?
本文介绍了从 UITableViewCell 到父 UITableView 的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从 UITableViewCell
中访问拥有的 UITableView
?
Is there any way to access the owning UITableView
from within a UITableViewCell
?
推荐答案
在单元格中存储对 tableView 的 weak
引用,您在 -tableView:cellForRowAtIndexPath:
表的数据源.
Store a weak
reference to the tableView in the cell, which you'd set in -tableView:cellForRowAtIndexPath:
of your table's dataSource.
这比依赖 self.superview
总是准确的 tableView 是脆弱的要好.谁知道 Apple 将来会如何重新组织 UITableView
的视图层次结构.
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.
这篇关于从 UITableViewCell 到父 UITableView 的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文