未在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];
}
答案 0 :(得分:0)
我刚试过你的代码而且它正常工作。
问题可能在于您调用此代码的位置。例如,它必须在viewDidAppear
中调用,而不是在viewDidLoad
中调用。