Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertAction handler running after delay

I'm trying to change my UIAlertViews to UIAlertControllers. I set up this action for it:

UIAlertAction *undoStopAction = [UIAlertAction actionWithTitle:@"Undo Stop"
                                                        style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action) {
                                                           [self undoStop];
                                                       }];

But, the handler doesn't run until about a second after the action is tapped. Is there any way to speed this up?

like image 666
Peter Carnesciali Avatar asked Sep 07 '15 15:09

Peter Carnesciali


2 Answers

The short delay is normal for Alert View (less than a second though). If this is not convenient for you, you can programmatically create a view that covers the screen with a label and a button, basically a customized alert view.

like image 165
ooenomel2003 Avatar answered Oct 15 '22 13:10

ooenomel2003


There is a semi-solution here:

The handler of a UIAlertAction is a bit too late - how can I make it immediate?

Basically, subclass the alert controller and run a handler on viewWillDisappear. You can store the handler block on your alert controller.

The problem with this solution is that you can't run a handler per button like you can if you add action(s) with UIAlertAction. So that's a major limitation.

However, this solution worked for me (because I was trying to add a background view behind the alert when the alert appeared and make it animate away with the alert when the alert disappeared...originally I tried to do it with the button tap, but that didn't work because of the handler being delayed).

like image 31
Ethan G Avatar answered Oct 15 '22 12:10

Ethan G