从UITableViewCell到父UITableView的引用? [英] Reference from UITableViewCell to parent UITableView?

查看:166
本文介绍了从UITableViewCell到父UITableView的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以从 UITableViewCell 中访问 UITableView

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

推荐答案

存储一个 weak 引用单元格中的tableView, c $ c> -tableView:cellForRowAtIndexPath:您的表的dataSource。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆