我如何在TableView的单元格中获取容器UITableView

|| 有什么方法可以访问单元格中包含当前UITableViewCell的UITableView?     
已邀请:
您可以上升视图层次结构,直到找到UITableView:
    UIView *v = self;
    while (v && ![v isKindOfClass:[UITableView class]]) v = v.superview;
    // v now holds the table view, or nil if there isn\'t one
尽管您可能应该质疑,为什么单元格到底需要在表视图中戳,以及是否有更简单的方法可以这样做。     
对于iOS 8+:
UITableView *tableView = cell.superview.superview;
    

要回复问题请先登录注册