I have an iOS app with a UIAlertController in the form of a action sheet being presented in my app when the user taps on a button.
It all works great, apart from one thing, the completion blocks don't get called for some reason.
Here is my code:
// Setup the alert information/type.
UIAlertController *action_view = [UIAlertController alertControllerWithTitle:@"Test title" message:@"test message" preferredStyle:UIAlertControllerStyleActionSheet];
// Create and add the cancel button.
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
[action_view dismissViewControllerAnimated:YES completion:^{
NSLog(@"asdhfgjk");
}];
}];
// Add the action button to the alert.
[action_view addAction:cancel];
// Present the alert to the user.
[self presentViewController:action_view animated:YES completion:nil];
If you run that code you will see the line which dismisses the controller wont run and neither will the NSLog
statement inside it. However, if you delete the NSLog
and set the completion block to nil, then it does run.... why???
Thanks for your time, Dan.