iOS UIAlertController Adding Text Field in UIAlertController like a prompt Box

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Swift

let alert = UIAlertController(title: "Hello",
                              message: "Welcome to the world of iOS",
                              preferredStyle: UIAlertControllerStyle.alert)
let defaultAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (action) in
        
}
defaultAction.isEnabled = false
alert.addAction(defaultAction)
    
alert.addTextFieldWithConfigurationHandler { (textField) in
     textField.delegate = self
}
    
present(alert, animated: true, completion: nil)

Objective-C

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Hello"
                                                               message:@"Welcome to the world of iOS"
                                                        preferredStyle:UIAlertControllerStyleAlert];
    
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" 
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction * action) {}];
    
defaultAction.enabled = NO;
[alert addAction:defaultAction];    
    
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
     textField.delegate = self;
}];        

[self presentViewController:alert animated:YES completion:nil];

enter image description here



Got any iOS Question?