2

我决定为 ios6 和 ios7 使用不同的故事板,所以我需要在代码中实例化故事板。我在应用程序委托中有这个方法- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

但什么也没发生,它总是实例化在iPadStoryboardiPad 模拟器上运行时命名的故事板,我已经从 info.plist 中删除了主界面。知道这里发生了什么吗?

- (void)loadStoryboards
{
    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

    UIStoryboard *mainStoryboard = nil;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))

        NSLog(@"1");
        if (iOSDeviceScreenSize.height == 480)
        {
            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone-ios5" bundle:nil];
        } else {
            NSLog(@"loading iPad storyboard");
            mainStoryboard = [UIStoryboard storyboardWithName:@"iPadStoryboardOS6" bundle:nil];
        }

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))

        NSLog(@"2");
        if (iOSDeviceScreenSize.height == 480)
        {

            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
        } else {
            mainStoryboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil];
        }


    self.initialViewController = [mainStoryboard instantiateInitialViewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.initialViewController;
    [self.window makeKeyAndVisible];
}
4

1 回答 1

1

请注意检查 iPad 的方式。480px 屏幕高度不覆盖 iPhone5。利用:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
于 2013-09-17T07:11:12.177 回答