Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a similar scenario as yours. My application uses a <code>UINavigationController</code> as the root view controller. If the user is logged in, I want to present him/her with <code>NotLoggedInViewController</code>, while if it's logged in I want to show the <code>LoggedInViewController</code>.</p> <p>In a storyboard a <code>UINavigationController</code> can only have one child, so you have to be able to programmatically assign another root view controller to it.</p> <p>I start by creating a custom navigation controller class, let's name it <code>MyNavigationController</code>. In the storyboard I assign this custom class to the navigation controller object.</p> <p>Still in the storyboard, I then model both view controllers, and connect one of them to the navigation controller object. Since I need to be able to access them from my code later on, I assign each of them an identifier using the XCode inspector on the right. These identifiers which can be arbitrary strings, but to things simple I just use the class names. </p> <p>Finally I then implement the <code>viewDidLoad</code> method on <code>MyNavigationController</code> class:</p> <pre><code>BOOL isLoggedIn = ...; - (void)viewDidLoad { id rootController; if (isLoggedIn) { rootController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoggedInViewController"]; } else { rootController = [self.storyboard instantiateViewControllerWithIdentifier:@"NotLoggedInViewController"]; } self.viewControllers = [NSArray arrayWithObjects:rootController, nil]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload