对单元格的父tableView的引用 [英] Reference to the parent tableView of a cell
本文介绍了对单元格的父tableView的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从tableview的单元格中引用父tableView?
Is there a way to have a reference of the parent tableView from the tableview's cell?
谢谢!
推荐答案
您可以将此方法添加到UITableViewCell的自定义子类中:
You can add this method to your custom subclass of UITableViewCell:
- (id)parentTableView {
UIView *v = [self superview];
UIView *previous = nil;
while (v && ![v isKindOfClass:[UITableView class]] && v != previous) {
previous = v;
v = [v superview];
}
return v == previous ? nil : v;
}
如果您不继承UITableViewCell,只需将上面代码中的 self
替换为对UITableViewCell的引用即可.
If you're not subclassing UITableViewCell, just replace self
in the code above with your reference to a UITableViewCell.
这篇关于对单元格的父tableView的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文