如何在 uitableviewcell 中获取索引路径文本字段?

how to get indexpath uitextfield inside tableviewcell?

我只知道像这样在 tableviewcell 中获取索引路径按钮

CGPoint center= [sender center]; CGPoint rootViewPoint = [[sender superview] convertPoint:center toView:_tableView1]; NSIndexPath *indexPath = [_tableView1 indexPathForRowAtPoint:rootViewPoint]; NSLog(@"%@",indexPath);

但我需要了解文本字段,感谢您对我的帮助!

要获取包含文本字段的单元格的 indexPath,您需要做几件事。

  1. 使 viewController class 成为 tableView 单元格中 textField 的委托
  2. 在你的 viewController 的 class 中实现 textField 的 delegateProtocoltextFieldDidBeginEditing 方法,像这样

- (void)textFieldDidBeginEditing:(UITextField *)textField { //Here you can you the same logic to find the indexPath of the cell like you use in case of a button. }

还有一个获取索引行的方法!

在 cellForRow 中这样做:

textField.tag = indexPath.row;

在 textField 方法中执行此操作:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    NSInteger row = textField.tag;    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
}