How to get a UITableViewCell from one of its subviews

前端 未结 4 1806
野性不改
野性不改 2020-12-17 16:39

I have a UITableView with a UITextField in each of the UITableViewCells. I have a method in my ViewController which handles the \"Did

4条回答
  •  执念已碎
    2020-12-17 17:06

    One slightly better way of doing it is to iterate up through the view hierarchy, checking for each superview if it's an UITableViewCell using the class method. That way you are not constrained by the number of superviews between your UITextField and the cell.

    Something along the lines of:

    UIView *view = field;
    while (view && ![view isKindOfClass:[UITableViewCell class]]){ 
        view = view.superview;
    }
    

提交回复
热议问题