我有一个包含多个文本字段的自定义单元格的表格 View 。我想通过单击 cellForRowAtIndexPath 中某处的按钮获取在文本字段中输入的值。是否可以 ?
上图是表格 View 单元格中文本字段的屏幕截图。
最佳答案
你可以得到UITextField
在 Tag
的帮助下功能性。
假设您有 3 个 UITextField
在 1 Cell
.
给Tag
至UITextField
在 cellForRowAtIndexPath
方法如下。
[cell.TextField1 setTag:(1000 + indexPath.row)];
[cell.TextField2 setTag:(5000 + indexPath.row)];
[cell.TextField3 setTag:(9000 + indexPath.row)];
获取
UITextField
您可以使用以下行。// Replace 1000 with your tag value
UITextField * textField = (UITextField *)[self.tableView viewWithTag:1000];
NSLog(@"Value of textfield = %@",[textField text]);
关于iOS:如何从 tableview 的自定义单元格中的 UITextField 访问值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27685648/