16

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?

3 Answers3

3

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.

  • Thanks. I previously had it as a UIAlertView, with a specific behavior when the art button was tapped. That has always been instant. I guess I'll keep doing that for now, even though it's deprecated. – Peter Carnesciali Sep 07 '15 at 21:20
1

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).

Ethan G
  • 1,293
  • 2
  • 14
  • 27
0

As implied by the comment left by Mr. T, it's possible that the handler is not being called on the main thread, which could explain the delay. Try embedding your handler code in :

dispatch_async(dispatch_get_main_queue()) {
<your code>
}

and see if you still get the delay.

pickwick
  • 3,104
  • 20
  • 30