1

I'm trying to be clever with my app.

I have 5 UITextField objects stacked on top of each other. I want the user to be able to enter stuff in the first UITextField and then press 'Next' on the keypad and have focus move to the next UITextField.

My strategy for this was to have an array of UITextField objects and when TextFieldOnEditingDidEnd gets called, I would call 'BecomeFirstResponder()' on the text field that appears AFTER the currently selected UITextField.

This strategy works fine on ios 7.x, however, it causes a STACK OVERFLOW in ios 6.

So, I am wondering if the fact that I call 'BecomeFirstResponder()' is forcing TextFieldOnEditDidEnd() to be called on the text field that I just made into the first responder.

Does anybody have any idea if the call to BecomeFirstResponder() forces a call on TextFieldOnEditDidEnd() ? Also, did this behavior change from iOS 6.x to iOS 7.x?

THANKS

4

2 回答 2

1

不完全回答你的问题,但另一个解决方案是:

设置tagtextFields. 开始形式 1, 2, 3... 然后,在代码中,textFieldShouldReturn:像这样实现:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    UIView * nextView = [textField.superview viewWithTag:textField.tag+1];
    if ([nextView respondsToSelector:@selector(becomeFirstResponder)])
        [nextView becomeFirstResponder];
    return NO;
}
于 2014-05-25T20:05:51.937 回答
1

适用于 iOS 6 和 iOS 7 的解决方案是使用延迟性能。在你的TextFieldOnEditingDidEnd,不要becomeFirstResponder直接调用;取而代之的是,在dispatch_after函数调用中以微小的延迟调用它。这将允许第一种方法在第二种方法开始之前结束,从而打破无限循环。

于 2014-05-26T01:59:26.267 回答