iphoneobjective-cioscocoauistoryboard

Getting Initial View Controller from Storyboard inside the App Delegate


I am trying to access the initial viewcontroller of my storyboard. It is a navigation controller which is wired up to a second viewcontroller via a seque. So after my application did finish launching I want to directly show the viewController that is connected through the segue. I tried it out with code like this but it doesn't work ...

UINavigationController *navController = (UINavigationController*)self.window.rootViewController;
[navController.topViewController performSegueWithIdentifier:@"showLoginScreen" sender:self];

What am I doing wrong?

4 years later:

If I look at my question again after 4 years, I honestly have no idea what my real problem was.


Solution

  • Be sure you have tick marked the

    is initial ViewController

    option for UINavigationController in storyBoard

    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UINavigationController * myStoryBoardInitialViewController = [storyboard instantiateInitialViewController];