How can i Get container UITableView in a cell of the TableView

喜你入骨 提交于 2020-01-04 07:55:34

问题


is any way to access the UITableView that contains current UITableViewCell in the cell?


回答1:


You can go up the view hierarchy until you find a 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

Although you should probably question why exactly the cell is needing to poke at the table view, and whether there is a more straightforward way to do it.




回答2:


For iOS 8+:

UITableView *tableView = cell.superview.superview;


来源:https://stackoverflow.com/questions/5745576/how-can-i-get-container-uitableview-in-a-cell-of-the-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!