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

OnkaPlonka
  • 1,232
  • 10
  • 19

3 Answers3

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.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
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];
OnkaPlonka
  • 1,232
  • 10
  • 19
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)
    }
Anfaje
  • 335
  • 4
  • 14