Search code examples
iosobjective-cuikit

Custom segue to specific sub-view in navigation controller hierarchy


I have a Sign Up wizard flow in a storyboard, it's a Navigation Controller (as the storyboard entry point) with ordinary Back/Next buttons in the navbar and then 4 sub-step Scenes with Show/Push segue transitions in a linear chain.

Normally I custom segue to the storyboard's navigation controller and the wizard then starts at the first step and everything's fine.

But from another point in the app I need to modally go to one of the sub-steps (not the first), and I don't want to copy/paste the entire view and the class controlling it into a whole new navigation controller chain, so I figured I could segue directly to it (and dynamically adjust what happens in the Back/Next buttons).

So I tried subclassing UIStoryboardSegue to do a custom segue for this, its sceneNamed method does something like this:

return [storyboard instantiateViewControllerWithIdentifier:sceneName];

and it works, but since we instantiate the sub-scene's View Controller and not the Navigation Controller, I see the scene but don't get the navbar..

On the other hand if I segue to the Navigation Controller it starts at the first linked Scene as usual.

Is there any way to fool UIKit into going to the Navigation Controller but getting it to start at a scene further down the normal hierarchy/flow ?

Yes I realize this is hackish; there are other solutions (I can programmatically add Back/Next buttons for example in this case). Just curious.


Solution

  • So why not hook up the segues like this:

    Navigation Controller (sign up) ->
      VC1 -> VC2 -> Terms of Service -> VC3
                           ↑
    Login View ->          |                          
         Navigation Controller
    

    This way, you simply have two different ways of reaching Terms of Service view controller, with no need to copy it. You can use a Storyboard Reference object to configure this without having a bunch of criss-crossing arrows marring the storyboard.