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];
}
私は何が間違っているのですか?