Reputation: 720
I'm having trouble with presentViewController method and its last parameter.
[self presentViewController:navigationController animated:YES completion:nil];
I'm new in objective-c syntax and can't find out what object should I pass to 'completion' parameter. (also didn't find any examples that use it)
I want to have callback method when my presented View Controller dismisses.
Thanks,
Milos
Upvotes: 4
Views: 27643
Reputation: 405
For anyone still reading this after all these years, I wanted to alert the user when an error happened inside a UIImagePickerController. Solution
if (error condition) {
[self dismissViewControllerAnimated:YES completion:^(void) {
dispatch_async(dispatch_get_main_queue(), ^{
// Alert the user here, for instance with a UIAlertController
});
}];
}
Upvotes: 0
Reputation: 533
Example of creating a completion block:
[self presentViewController:navigationController
animated:YES
completion:^(){
//put your code here
}];
This block does not take parameters. other blocks may take parameters and you can define them like this example:
^(BOOL bFinished){
//put your code here
}
Upvotes: 17
Reputation: 119272
This method isn't going to give you what you want. The completion block is for when the view controller has completed presenting, not when it is dismissed. You'll need to use a different pattern, such as delegation, to get a callback when the controller is dismissed.
The completion handler is called after the viewDidAppear: method is called on the presented view controller.
See presentViewController:animated:completion:
Upvotes: 11