我在 UITableView
的自定义单元格中有两个 UITextFields
。
我需要编辑和存储文本字段的值。
当我在 UITextField
中单击时,我必须知道它所属的行,以便将值保存到本地数组的正确记录中。
如何获取 textField 的行索引?
我试过了:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
currentRow = [self.tableView indexPathForSelectedRow].row;
}
但当我在 UITextFieldRow 中单击时,currentRow 并没有改变。只有当我单击(选择)整行时它才会改变...
最佳答案
文本字段没有向 TableView 发送触摸事件,因此 indexPathForSelectedRow 不起作用。您可以使用:
CGPoint textFieldOrigin = [self.tableView convertPoint:textField.bounds.origin fromView:textField];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:textFieldOrigin];
关于ios - 获取 UITableViewCell 中 UITextField 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19403768/