iphone - 我如何在 TableView 的单元格中获取容器 UITableView

标签 iphone cocoa-touch uitableview

有什么方法可以访问单元格中包含当前 UITableViewCell 的 UITableView 吗?

最佳答案

您可以向上查看 View 层次结构,直到找到 UITableView:

    UIView *v = self;
    while (v && ![v isKindOfClass:[UITableView class]]) v = v.superview;
    // v now holds the table view, or nil if there isn't one

尽管您可能应该质疑为什么单元格需要戳 TableView ,以及是否有更直接的方法来做到这一点。

关于iphone - 我如何在 TableView 的单元格中获取容器 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5745576/

相关文章:

iphone - CoreAnimation 和 OpenGL ES 驱动工具的区别 - iPhone

objective-c - 如何将 Facebook 粉丝页面集成到 iPhone 应用程序中?

iphone - iPhone应用程序:如何使用MPMoviePlayerController在应用程序中播放Youtube视频

ios - NSLayoutConstraint - super View 的动态高度

原型(prototype)单元格内按钮上的 iOS UIButton 标题文本

iphone - 在iOS下以实用方式仅播放YouTube API中的音频

iphone - 右对齐 EntryElement

iphone - 保留图像数组

ios - 使用 iPhone 接收短信通知

ios - 在搜索期间向 tableView 添加部分和行,如 Tweetbot 中所示