Get basic storyboard in universal app

Trying my hand in a universal project, I would like to load vc by id from the storyboard. Is there a way to avoid explicitly checking the idiom when accessing the storyboard.

This ugly code works ....

UIStoryboard *storyboard; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; } else { storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil]; } UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"]; 

But yuck. The literal literal main storyboard is complex enough to look at (I don’t know why the project cannot save the main storyboard setting so that applications can say [UIStoryboard mainStoryboard];), but explicitly checking the idiom is too much of a bridge.

Is there any hidden intelligence (comparable to the suffix "@ 2x" that supports retina displays) that could clear this code?

+7
source share
1 answer

Assuming you are running published code from another view controller, you can always get the current storyboard through [self storyboard] , where self is any instance of the UIViewController.

+16
source

All Articles