If you use a Storyboard segue to present your view controller, you can reject it using the Unwind Segue. Segue unwinding is a special kind of segue that unwinds presented view controllers in front of the host.
To do this, you must create a method in the view of the view controller with the following signature:
- (IBAction)unwindAction:(UIStoryboardSegue*)unwindSegue;
This is different from the standard IBAction , because the parameter type is UIStoryboardSegue* instead of the usual id type (you don't need to call it unwindSegue: it can be modalViewFinished: or something else you like - the important part is that it has an IBAction return type and parameter type UIStoryboardSegue* ).
Once you have defined this method, in your storyboard you control the drag from the modal view controller icon (under its view, in a small line of icons) and release the connection on the green exit sign. This will create a spread, which you must give an identifier in the attribute inspector. Unwind segues will not be displayed visually in the storyboard canvas, so you will have to find it in the list of items on the left side of the canvas (by default it crashed, expand it by clicking the small circular button in the lower left corner of the canvasβs manual corner).
Once you do this, instead of calling [self dismissViewControllerAnimated:YES completion:nil] just call [self performSegue:<Identifier you gave the unwind segue>] . During this process, the unwindAction: method defined on the view presentation controller and the prepareForSegue: method on the modal view controller must be called. You can do everything you need to do in these methods (for example, calling the foo method from unwindSegue: .
source share