1

我有一个表,其中添加了 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;
}
4

1 回答 1

0

好的,我找到了一个令人满意的解决方法,似乎允许运行循环在请求动画删除部分修复问题之前执行。我猜这是一个苹果虫?对于其他担心这个问题的人——我在 iPad 上运行 iOS3.2.1。

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (_editing == 1) {
        [self performSelector:@selector(hideFinalSection) withObject:nil afterDelay:0.0f];
    }
    else {
        _editing--;
    }

    self.navigationItem.rightBarButtonItem = nil;

        // do something with the text here...

    return YES;
}

- (void) hideFinalSection {
    if (!(--_editing)) { 
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
    }
}
于 2010-10-22T14:07:00.740 回答