Robert
Robert

Reputation: 1589

Multiple Storyboards - Multiple Navigation Controllers

I am breaking up my project into multiple storyboards. I have a login storyboard with a navigation controller. The last step "Complete Registration" takes you to main.storyboard.

This leaves the navigation controller in place, and the back button takes you back to register. I obviously don't want that. I know I can hide the bar by using:

self.navigationController?.navigationBarHidden = true

But how can I leave the navigation controller?

Any help would be greatly appreciated!

Upvotes: 1

Views: 2218

Answers (2)

Jeff Lewis
Jeff Lewis

Reputation: 2866

The easiest and most correct way to do this would be to make your login screen a modal view. If you don't want to give your user the ability to go back, then you shouldn't use a push segue. You should use a modal view.

In the iOS Human Interface guidelines it says that modal views should be used for "a self-contained task [that] must be completed—or explicitly abandoned—to avoid leaving the user’s data in an ambiguous state."

A modal view will make it so your login and your main screen have to be in separate Navigation Controllers.

Upvotes: 2

Bret Smith
Bret Smith

Reputation: 88

In the completion handler of the "Complete Registration" action you'll want to use the following code.

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = storyboard.instantiateInitialViewController() as! (TypeOfViewController)
        self.presentViewController(viewController, animated: true, completion: nil)

If your main.storyboard is already embedded in a NavigationController (Initial view controller is a UINavigationController) then you'll have to do that a little bit differently.

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = storyboard.instantiateInitialViewController()
        self.presentViewController(viewController, animated: true, completion: nil)

Upvotes: 1

Related Questions