3

アラートビューでテキストフィールドのキーボードタイプを表示する際に問題があります。テンキーキーボードを表示したいのですが、うまくいきません。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

switch (alertView.tag) {
    case 1:
        if (buttonIndex == 0) {
            UITextField *textField = [alertView textFieldAtIndex:0];
            textField.keyboardType = UIKeyboardTypeNumberPad;
            [self performSelectorOnMainThread:@selector(ProcessDeleteTransaction:) withObject:textField.text waitUntilDone:NO];
        }
        break;
    case 2:
        [self.navigationController popToRootViewControllerAnimated:YES];
        break;
    default:
        break;
}

}

4

4 に答える 4

7

これを試して:

UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Howdie" message:@"msg" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
a.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [a textFieldAtIndex:0];
assert(textField);
textField.keyboardType = UIKeyboardTypeNumberPad;

[a show];
于 2013-06-08T13:33:14.537 に答える
1

ご存知のよう- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndexに、ユーザーがアラート ビューのボタンをクリックしたときに呼び出されるデリゲート メソッドですが、 ..そのtextField.keyboardType前に設定する必要があるため、 becomeFirstResponderkeyboardType プロパティを一度設定する必要があります。[[UIAlertView alloc] init]

于 2013-06-08T13:34:34.187 に答える
1

これを試して:

- (void)willPresentAlertView:(UIAlertView *)alertView {
    [[alertView textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeDecimalPad];
    [[alertView textFieldAtIndex:0] becomeFirstResponder];
}
于 2016-07-25T14:15:31.533 に答える