2

Hi I have created two storyboard files and I have no Idea how I would switch between them. For switching within one storyboard I set the Identifier and use this code:

[self performSegueWithIdentifier:@"identifier" sender:self];

this code crashes the app when it is used to switch storyboards.

Please help

0

3 Answers 3

10

Updated Answer for iOS 9.0

You can use a storyboard reference in a storyboard to set the destination of a segue to a view controller in another storyboard. Drag a storyboard reference from the Object library to your source storyboard. Configure it with the name of the destination storyboard and the identifier of the destination view controller in that storyboard. Then you can use the reference as the destination for segues in the source storyboard.

See “Adding a Reference to Another Storyboard” in Storyboard Help for more details.

Original Answer

Take a look at the UIStoryboard Class Reference.

You can load a storyboard by name using +[UIStoryboard storyboardWithName:bundle:]. Once you have the storyboard object, you can instantiate one of its view controllers by sending it instantiateInitialViewController or instantiateViewControllerWithIdentifier:. Then you can do whatever you want with that view controller: present it modally, push it on a navigation controller, add it to a tab bar controller, etc.

You cannot create a segue between scenes in different storyboards, so you cannot use performSegueWithIdentifier:sender: to transition from a scene in one storyboard to a scene in another storyboard.

0
7

I've found the answer to my own question!

Here's the code for my problem:

-(void)viewDidLoad {

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        CGSize result = [[UIScreen mainScreen] bounds].size;

        if(result.height == 480){}
        if(result.height == 568){[self performSelector:@selector(inch4) withObject:nil afterDelay:0];}}}



-(void)inch4 {

    UIStoryboard *storyBoard;

    storyBoard = [UIStoryboard storyboardWithName:@"iPhone4inch" bundle:nil];
    UINavigationController *init4inchViewController = [storyBoard instantiateViewControllerWithIdentifier:@"MainMenu4inch"];
    [self presentModalViewController:init4inchViewController animated:NO];

}

here's the code to switch storyboard files:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboard2" bundle:nil];
[self presentModalViewController:[storyboard instantiateViewControllerWithIdentifier:@"storyboard2initialviewcontroller"] animated:NO];
3
  • You should probably accept on of these answers. Both are the same and correct. Dec 15, 2012 at 23:04
  • It says I can tomorrow when i try
    – OnkaPlonka
    Dec 16, 2012 at 9:17
  • To add identifier to your storyboard follow this link Sep 25, 2014 at 6:50
3

In swift, this is as simple as below. :)

    let sb = UIStoryboard(name: "DestinationStoryboard", bundle: nil)
    let vc = sb.instantiateInitialViewController() {
       present(vc, animated: true, completion: nil)
    }
1
  • Man, you cannot believe how much I was looking for this answer. Thanks!
    – Antonio
    Apr 20, 2017 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.