Search code examples
iosmodalviewcontrollerseguepushviewcontrolleruistoryboardsegue

How to break chain of navigation controllers


In my project I have following chain of navigation controllers

Home controller -> Table View controller -> Page View Controller 

Now in Page View Controller after all the pages are viewed at least once - I want to automatically go to completely different view which is Quiz View.

Quiz Controller-> Result Controller -> Another Quiz Controller-> Result controller -> Yet another quiz Controller -> Result Controller -> Back to Home Controller

There are 3 different quizzes. And after taking all the three quizzes I want to go back to the home. Also in each result controller I want to provide an option to go back to home. And when home view is reached it should be a fresh restart.

At any intermediate stage I do not want to go back through chain-i.e intermediate controllers are not required. So what segue should be used for this purpose?

I thought against push segue because it will have stack of all the previous view controllers. Is there any way we can stop chain of navigation controllers and start new one?

And as a good programming practice if modal view is used parent view is supposed to dismiss child view. But in this case I do not wish to go back instead I want start new navigation controller chain from this modal view. But still want to go back to home controller directly at the end.


Solution

  • I ended up using storyboard unwind feature.

    Implementing a method in the home controller and then connecting a segue to that method from any source controller did the trick.

    Tutorial on Unwinding Storyboard Segues