× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Unwinding from an arbitrarily-instantiated view controll

Thomas Catterall
Jun 04, 2015
<p>Scenario:</p> <p>You have two view controllers, A and B. A presents B, and B can unwind to A. Now imagine you have started the app and skipped A, instantiating B directly. How can you unwind back to A?</p> <p>Unwinding generally expects a pre-existing view controller. However, you can hook into the API used to find the view controller and create the view controller at that point.</p> <p>Consider embedding View Controller B inside an "UnwindToVCA" controller. This view controller will serve as the `nextResponder` to B. By implementing `viewControllerForUnwindSegueAction:fromViewController:withSender:` you can return A.</p> <p>Be careful to ensure you provide the right segues, too, using `segueForUnwindingToViewController`. You'll need to define your animations carefully and take into account the weird state your application may be in.</p>
comments powered by Disqus