我的UITableView
(大约12个部分)中有多个部分,每个部分都有一行或多行。当我选择一行时,如何在UITextField
委托方法中获取节号?
答案 0 :(得分:3)
如果您在单元格中添加了文本字段,如
[cell.contentview addSubview:yourtextfield];
然后在文本字段代表
UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];
NSLog(@"your Indexpath %d",indexPath.section);
答案 1 :(得分:1)
当用户选择行时,您的代码需要处理对
的调用- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
** your code here**
}
传递给此方法的indexPath
包含section和row。找到如何使用它的最好方法是查看NSIndexPath的文档,但我相信像
indexPath.section
是你需要的。
答案 2 :(得分:1)
试试这个: -
-(void) textFieldDidBeginEditing:(UITextField *)textField {
UITableViewCell *clickedCell = (UITableViewCell *)[textField superview];
int section = [topicTable indexPathForCell:clickedCell].section;
NSLog(@"section %d", section);
}
答案 3 :(得分:0)
显示标签值,文本字段值,尝试此代码(使用标签)
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"%d : %@", textField.tag,textField.text);
[textField resignFirstResponder];
}
答案 4 :(得分:0)
UITableViewCell *cell = (UITableViewCell *)[[textField superview]superview];
NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];
NSLog(@"your Indexpath %d",indexPath.section);
但是我建议您在使用uitableviewcell
执行标记操作时创建自定义单元格答案 5 :(得分:-1)
如果您已在界面构建器中手动创建表视图,即使用静态单元格,则可以在每个UITextField中使用标记,然后在委托方法中检查它。
对于12个部分,您可以将标记编号为,例如1203是第12节中的第3行,或600是第6节中的第0行。