Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying a UIStoryboard

How do you identify a UIStoryboard?

The class has methods which create and instantiate but I don't see an @property with something like name. E.g.

Getting a Storyboard Object

+ storyboardWithName:bundle:

Instantiating Storyboard View Controllers

– instantiateInitialViewController
– instantiateViewControllerWithIdentifier:

Any suggestions?

==== UPDATE

I was hoping for something like self.storyboard.name or [self.storyboard description], e.g.:

NSLog(@"This Storyboard is: %@", self.storyboard.name);

Perhaps it's not meant to be.

like image 988
Snowcrash Avatar asked Apr 17 '13 13:04

Snowcrash


People also ask

How do I find the storyboard ID?

In the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.

What are storyboard identifiers for?

A storyboard ID does exactly what the name implies: it identifies. Just that it identifies a view controller in a storyboard file. It is how the storyboard knows which view controller is which.

What is instantiateViewController in Swift?

instantiateViewController(withIdentifier:) Creates the view controller with the specified identifier and initializes it with the data from the storyboard.


1 Answers

You can identify a storyboard by its name in the project navigator:

enter image description here

You can identify a view controller from a storyboard by setting its Storyboard ID in the identity inspector in interface builder:

enter image description here

Once you have these, then you can access them through your code:

UIStoryboard *iPhoneStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
ViewController *firstViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:@"FirstViewController"];
like image 193
Bryan Luby Avatar answered Oct 18 '22 07:10

Bryan Luby