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?
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With