How to get a UITableViewCell from one of its subviews

前端 未结 4 1804
野性不改
野性不改 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:25

    Since your goal is really to get the index path for the text field, you could do this:

    - (IBAction)itemFinishedEditing:(UITextField *)field {
        [field resignFirstResponder];
    
        CGPoint pointInTable = [field convertPoint:field.bounds.origin toView:_tableView];    
    
        NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:pointInTable];
    
        _list.items[indexPath.row] = field.text;
    }
    

提交回复
热议问题