在UIAlertController

时间:2017-10-25 07:43:37

标签: objective-c iphone xcode9

未在UIAlertController中添加UITextfield

这是我的代码:

if ([UIAlertController class]) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Forgot Password" message:nil preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){[![enter image description here][1]][1]
                NSString *str = @"OK Pressed";
            }];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
                NSString *str = @"otherAction Pressed";
            }];
            [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                textField.placeholder = @"placeHolderText";
                textField.keyboardType = UIKeyboardTypeDefault;
            }];
            [alert addAction:okAction];
            [alert addAction:cancelAction];
            [self presentViewController:alert animated:YES completion:nil];
        }

enter image description here

1 个答案:

答案 0 :(得分:0)

我刚试过你的代码而且它正常工作。

问题可能在于您调用此代码的位置。例如,它必须在viewDidAppear中调用,而不是在viewDidLoad中调用。