mday
mday

Reputation: 427

SWIFT: Switch rootviewcontroller

I have a single storyboard with two different flows:

  1. A login flow that a non-logged in user must use until logged in. This view utilizes a navigation controller.

  2. A application flow that all logged in users use. The view leverages a UITabBarController for the app.

My objective is to direct logged in users to the regular application flow if we detect they are logged in in the app delegate. Similarly, if not logged in we want the user to utilize the login flow.

My issue is that I can't seem to set and load these different views from the app delegate.

I have tried the following code, but it doesn't seem to work:

```

var rootView: MyRootViewController = MyRootViewController()

 if let window = self.window{
        window.rootViewController = rootView
 }

 return true

```

One thing I am wondering is is my rootviewcontroller should be the navigationcontroller or UITabbarController or one of the subviews under those...

Upvotes: 0

Views: 507

Answers (1)

gabbler
gabbler

Reputation: 13766

Set the navigationController as rootViewController. Use instantiateViewControllerWithIdentifier to get a view controller,which can be login or tabbar controller,then push the view controller on the navigation stack, which can be done through navigationController's setViewControllers method. You might want to hide the navigation bar when app launches.

Upvotes: 2

Related Questions