开发者

4 digit code entry like in remote app

I would to to do a 4 digit code entry like app does in the remote app to verify to iTunes library. Currently have 4 UITextFields, but am running into problems automatically moving the cursor to the next text field.

Using this code currently but this moves the cursor then places the text in the new first responder instead of the correct one:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRa开发者_StackOverflow中文版nge)range replacementString:(NSString *)string {
    if ([string length] > 0) {
        if (codeText1 == textField) {
            [codeText2 becomeFirstResponder];
        } else if (codeText2 == textField) {
            [codeText3 becomeFirstResponder];
        } else if (codeText3 == textField) {
            [codeText4 becomeFirstResponder];
        }
    }

    return YES;
}


Regardless of the platform, it's always dicey to monkey with focus in the middle of the events that report on focus. I would instead implement UITextInputDelegate and handle (void)textDidChange:(id )textInput.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜