Search code examples
iosnotificationspresentviewcontroller

Get notified when a presented ViewController is dismissed


I'm presenting a ViewController using presentViewController. I need to perform some operations when the presented ViewController dismisses itself. At the moment, I defined a protocol for the presenting ViewController and I call the corresponding method in the completion block of dismissViewControllerAnimated in the presented ViewController. Is there a more straightforward way?


Solution

  • You could use delegation and have the delegate perform the appropriate methods right before calling dismissViewController, use an unwind segue instead of dismissViewController, or do it the way you're doing it currently. It sounds like you're doing it the right way if you want the operations to be run immediately after the presented view controller dismisses itself; that's why the completion block exists in dismissViewController. Using delegation means the operations would be run immediately prior to the presented view controller's dismissal.