我有一个 UITableViewCell
链接到一个对象,我需要判断单元格是否可见。根据我所做的研究,这意味着我需要以某种方式访问包含它的 UITableView
(从那里,有几种方法可以检查它是否可见)。所以我想知道 UITableViewCell
是否有指向 UITableView
的指针,或者是否有任何其他方法可以从单元格中获取指针?
最佳答案
为了避免检查 iOS 版本,迭代地从单元格的 View 向上遍历 super View ,直到找到 UITableView:
Objective-C
id view = [cellInstance superview];
while (view && [view isKindOfClass:[UITableView class]] == NO) {
view = [view superview];
}
UITableView *tableView = (UITableView *)view;
swift
var view = cellInstance.superview
while (view != nil && (view as? UITableView) == nil) {
view = view?.superview
}
if let tableView = view as? UITableView {
tableView.beginUpdates()
tableView.endUpdates()
}
关于iphone - 如何从 UITableViewCell 获取 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15711645/