如何从 UITableViewCell 获取 UITableView? [英] How to get UITableView from UITableViewCell?
问题描述
我有一个 UITableViewCell
链接到一个对象,我需要判断该单元格是否可见.根据我所做的研究,这意味着我需要以某种方式访问包含它的 UITableView
(从那里,有几种方法可以检查它是否可见).所以我想知道 UITableViewCell
是否有一个指向 UITableView
的指针,或者是否有任何其他方法可以从单元格中获取指针?
I have a UITableViewCell
which is linked to an object and I need to tell if the cell is visible. From the research I've done, this means I need to somehow access the UITableView
that contains it (from there, there are several ways to check if it's visible). So I'm wondering if UITableViewCell
has a pointer to the UITableView
, or if there was any other way to get a pointer from the cell?
推荐答案
为了避免检查 iOS 版本,从单元格的视图中迭代地走上超级视图,直到找到 UITableView:
To avoid checking the iOS version, iteratively walk up the superviews from the cell's view until a UITableView is found:
id view = [tableViewCellInstance superview];
while (view && [view isKindOfClass:[UITableView class]] == NO) {
view = [view superview];
}
UITableView *tableView = (UITableView *)view;
这篇关于如何从 UITableViewCell 获取 UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!