-1

UITextfield is not getting added in UIAlertController

Here is my code :

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

Roshan Sah
  • 137
  • 10

1 Answers1

1

I just tried you code and it works normally.

The problem, maybe, is in place where you calling this code. Like, for example, it must be called in viewDidAppear and not in viewDidLoad.

Anton Malmygin
  • 3,406
  • 2
  • 25
  • 31