Will Larche
Will Larche

Reputation: 3149

How to get out of a UIStoryboard initialized in code

I have a main container controller that initializes child view controllers.

I'm trying to learn to use UIStoryboards tho and I'm stumped as to how to get out of a storyboard.

Here's the flow:

enter image description here

Once I get to the end of a storyboard's scenes, how should I get out of storyboard and back to my container controller?

Should I keep a pointer to the storyboard? What would I do with it?

Should I keep a pointer to the initial view controller (which is the one I explicitly add as child)? It's .view won't be on screen at the end so I don't know what I would do with that either.

Upvotes: 0

Views: 126

Answers (2)

user1494556
user1494556

Reputation:

Try looping through the childViewControllers

for (UIViewController *vc in self.childViewControllers) {
    // do something
}

Upvotes: 1

JonahGabriel
JonahGabriel

Reputation: 3104

What do you mean "out of a storyboard". You don't need to save a pointer to your storyboard as self.storyboard should work in most cases. If you use a UINavigationController as your entry point in your storyboard with your initial view controller as it's root view, all you have to do to get back to your initial controller is

[self.navigationController popToRootViewControllerAnimated:YES];

Also, you can get a reference to your storyboard like this as well:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

Upvotes: 0

Related Questions