开发者

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.

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜