简体   繁体   中英

Using multiple Storyboards in Xcode

I have created 5 extra Storyboards and I have deleted the main storyboard. This is because I would like to have 5 separate storyboards for the iPhone and iPad to match 5 different screen sizes. So far I have one for the iPhone 3.5 inch, one for the iPhone 4 inch, one for the iPhone 4.7 inch, one for the iPhone 5.5 inch and one for the iPad. I have put the code bellow in to link it all up and make it work. However, it doesn't work when you try and build the project. There is no errors but lets say I go into the iPhone 3.5 inch storyboard and I add a UIViewController and a Button or label, then when you build the project it goes to your launch screen and then it doesn't do anything from there. I have put the starting arrow in at the UIViewController but I cannot get anything to come up apart from the launch screen. I have tried this on all the storyboards and their simulators. I am wondering if I have missed something out in the code but I am not sure.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = nil;
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad) {
    storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPad" bundle:nil];//iPad
} else {
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    if (screenSize.height == 480){
        storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4S" bundle:nil];//iPhone 3.5inch
    } else
        if (screenSize.height == 568){
            storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone5/5C/5S" bundle:nil];//iPhone 4inch
        }
        else
        { if (screenSize.height == 667){
            storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone6" bundle:nil];//iPhone 4.7inch
            } else
                if (screenSize.height == 736){
                    storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone6Plus" bundle:nil];//iPhone 5.5inch
                } else
                    //default storyboard
                storyboard = [UIStoryboard storyboardWithName:@"Main.Storyboard" bundle:nil];
            }
}
    self.window.rootViewController = [storyboard instantiateInitialViewController];
    [self.window makeKeyAndVisible];

return YES;
}

Find your info.plist file in your project and remove the line called "Main storyboard file base name". 在此处输入图片说明

Also, you forgot to create the window (credits to rdelmar ).

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

I strongly advise you to look into Auto Layout and Size Classes . Using these two, you can support all screen sizes within one single Storyboard. It's a bit hard to get in the beginning, but it'll definitely be worth it in the long run.

There's a video about this from the most recent WWDC called Building Adaptive Apps with UIKit .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM