Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIStoryboard: What's the Correct Way to Get the Active Storyboard?

I am currently furiously digging through all the docs, and haven't quite found what I'm looking for. I suspect it is a real d'oh! answer.

I simply need to find the active storyboard in the main bundle, and want to know the best way to do this.

This is so that I can use the [UIStoryboard storyboardWithName:@"XXX" bundle:mainBundle] to extract the running storyboard.

I know how to kludge it by switching on the idiom, but I feel that this is a...kludge.

What's a correct way of doing this?

like image 442
Chris Marshall Avatar asked Mar 24 '12 16:03

Chris Marshall


People also ask

How do I change the Storyboard name in Xcode?

If you want to change the name of a storyboard, rename it by performing these steps: Select Modeling > Storyboard from the toolbar. Right click on the storyboard to rename and select Rename Storyboard… from the popup menu.


1 Answers

In case you want to get the active storyboard for a viewController, there's a storyboard property. This is how I solved it, instead of making a new instance:

LoginViewController *vc = [navController.storyboard instantiateViewControllerWithIdentifier:@"firstLaunch"]; [navController presentModalViewController:vc animated:YES]; 

In Swift you'd call:

let loginViewController = navigationController?.storyboard?.instantiateViewController(withIdentifier: "firstLaunch") as! LoginViewController navigationController?.present(loginViewController, animated: true, completion: nil) 

You could also be a lot safer by using guards against the navigation controller and the storyboard. I've used as! so as to guarantee that you're getting a LoginController.

like image 111
olivaresF Avatar answered Oct 06 '22 05:10

olivaresF