我有一个表,其中添加了 3 个 UITextFields 到单元格的内容视图(每节 1 行)。我插入了第 4 部分,以便可以将特定字段滚动到键盘上方。
我遇到的问题(仅在 iPad 上)是当其中一个文本字段具有 firstResponder 时,当用户点击另一个字段时它不会放弃它。ipad 上的响应器链是否存在差异?在我的视图控制器的波纹管代码中,UITextFieldDelegate - 触摸另一个字段时不会调用 textFieldShouldEndEditing。按下完成按钮按预期工作(除非已触摸另一个字段)。
下面的代码有什么问题吗?
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (!_editing++) {
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
}
// scroll to section number in the text fields tag
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:textField.tag] atScrollPosition:UITableViewScrollPositionTop animated:YES];
return YES;
}
- (void) textFieldDidBeginEditing:(UITextField *)textField {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:textField action:@selector(resignFirstResponder)] autorelease];
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
if (_editing-- == 1) {
//
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
}
self.navigationItem.rightBarButtonItem = nil;
// do something with the text here...
return YES;
}