1

UIAlertView内の最初のフォーカスをパスワードフィールドに設定しようとしていますが、これまでに試したすべてが機能しませんでした。

私はこのコードが機能することを望んでいましたが、私が理解できない間違いがあります:

- (void)showLoginFormWithUsername:(NSString*)username andPassword:(NSString*)password {
    UIAlertView *loginView = [[UIAlertView alloc] initWithTitle:@"Login"
                                                        message:@"Please enter your login data."
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Login", nil];

    loginView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

    // get TextFields
    UITextField *usernameField = [loginView textFieldAtIndex:0];
    UITextField *passwordField = [loginView textFieldAtIndex:1];

    // set text
    if (username)
        usernameField.text = username;
    if (password)
        passwordField.text = password;

    // set focus
    if (usernameField.hasText && !passwordField.hasText)
        [passwordField becomeFirstResponder];

    [loginView show];
}

私は何が間違っているのですか?

4

1 に答える 1

0

アラートビューをレスポンダーにしようとする前に、アラートビューが表示されるのを待っているわけではありません。代わりに、didPresentAlertView:メソッドでこれを実行します。

于 2012-11-20T01:03:26.730 に答える