Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - I would like UIAlertController to not be removed when button clicked

I would like to present a UIAlertController with 2 buttons.

One button should close the alert and the second should perform an action but remain the alert on screen. Is there some configuration that can be done to action that it won't close the alert?

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title"
                                                               message:@"message"
                                                        preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Do Something"
                                          style:UIAlertActionStyleDefault
                                        handler:^(UIAlertAction *action) {
    //Pressing this button, should not remove alert from screen
                                        }]];

[alert addAction:[UIAlertAction actionWithTitle:@"Close"
                                          style:UIAlertActionStyleDefault
                                        handler:^(UIAlertAction *action) {
    //Regular functionality- pressing removes alert from screen 
                                        }]];


[alert show];

This (Prevent UIAlertController to dismiss) was suggested as possible answer, but the question deals with text field. I need one of the action buttons to not close the alert when pressed.

like image 502
Luda Avatar asked May 03 '18 15:05

Luda


1 Answers

You can't do this.

Only one solution is to create a custom view controller that will look like native UIAlertController.

like image 148
Ivan Smetanin Avatar answered Sep 27 '22 22:09

Ivan Smetanin