假设的UITextField加入到的UITableViewCell像下面
UITableViewCell *cell;
UITextField *textField;
...
textField.tag = kTAG_TEXTFIELD;
[cell.contentView addSubview:textField];
...
您可以通过
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
if([textField.superView.superView isKindOfClass:[UITableViewCell class]]) {
UITableViewCell *cell = (UITableViewCell *)textField.superView.superView;
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
}
...
获取当前索引路径然后下一行的的UITextField将
NSIndexPath *indexPathNextRow = [NSIndexPath indexPathForRow:(indexPath.row+1) inSection:indexPath.section];
UITableViewCell *cellNextRow = (UITableViewCell *)[self.myTableView cellForRowAtIndexPath:indexPathNextRow];
UITextField *textFieldNextRow = (UITextField *)[cellNextRow.contentView viewWithTag:kTAG_TEXTFIELD];
希望它能帮助!
谢谢!但我只是跟踪当前的文本框,因为有很多文本框。我能以某种方式获得下一个文本字段而不使用标签吗? – Mrbiggerm 2010-05-13 09:14:18
当然,只要保留对它们的引用,“UITextField * firstTextField”或使用数组等等。但标记可能是识别委托文本字段的最快方法。 – 2010-05-13 09:19:13
但是,如果我不想跟踪所有文本框或标签?我能否以某种方式获取当前正在编辑的文本字段所在的当前单元格,然后获取indexpath? – Mrbiggerm 2010-05-13 10:13:15