Home:ALL Converter>Who should be the one dismissing the view controller?

Who should be the one dismissing the view controller?

Ask Time:2016-05-06T15:53:59         Author:Puneet

Json Formatter

I wanted to ask who should be the one dismissing a presented view controller?

Lets say I presented a view controller and on an IBAction in that view controller, I want to dismiss it. Should I be passing that responsibility to the presenting view controller by creating a delegate method or I should be just calling the dismissViewController:animated: on itself, which inturn anyways asks its presenting view controller to dismiss the presented view controller?

So, I think these are some clear cut cases where the presenting view controller should be the one dismissing the presented view controller

  1. The presented view controller is passing some data back to the presenting view controller.
  2. The presenting view controller wants to do something after the dismissal of the presented view controller.
  3. The presenting view controller to handle how the dismissal is going to happen, does it need some kind of animation

What if the presented view controller first checks if the presenting view controller actually wants to take the responsibility of dismissal by checking the presenting view controller implemented the dismissal delegate method? Is it really worth putting the complexity of conditional logic here?

And yes, I tried reading it on other forums and questions like

Dismissing a Presented View Controller

Dismissing Modal View Controllers

Present and dismiss modal view controller

view controllers: presentation, dismissal

But couldn't really find the right logical answer.

Author:Puneet,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37067158/who-should-be-the-one-dismissing-the-view-controller
yy