我已经创建了一个自定义的 UITableViewCell
,单元格有多个文本字段,现在我想访问这些 UITextFields
中的字符串或数据。我知道我可以在 didSelectRowAtIndexPath
上获取单元格,但我需要在“保存”方法上获取文本。
最佳答案
假设您有四个带有标签 100 等到 104 的文本字段。 您将使用 Counter 显示您在 tableview 中有多少个单元格。
for (int i=0; iLessThanCounter; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow: i inSection: 0];
UITableViewCell *cell = [mytableview cellForRowAtIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UITextField class]]){
UITextField* txtField = (UITextField *)view;
if (txtField.tag == 100) {
NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
}
if (txtField.tag == 101) {
NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
}
if (txtField.tag == 102) {
NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
}
if (txtField.tag == 103) {
NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
}
if (txtField.tag == 104) {
NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
} // End of isKindofClass
} // End of Cell Sub View
}// Counter Loop
}
关于iphone - 在 UITableView 自定义单元格中获取值表单文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11666588/