2

Is there a way to have a reference of the parent tableView from the tableview's cell?

Thanks!

Abramodj
  • 5,709
  • 9
  • 49
  • 75

2 Answers2

5

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.

odrm
  • 5,149
  • 1
  • 18
  • 13
0

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.

}
visakh7
  • 26,380
  • 8
  • 55
  • 69