Reference to the parent tableView of a cell
Is there a way to have a reference of the parent tab开发者_如何转开发leView from the tableview's cell?
Thanks!
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;
}
If you're not subclassing UITableViewCell, just replace self
in the code above with your reference to a UITableViewCell.
If you are accessing the cell through the didSelectRowATIndexPath:
you can get it easily as
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// here tableView is the one you want.
}
精彩评论