如何在没有App Delegate的plist的情况下手动选择初始故事板?

时间:2015-04-23 18:56:21

标签: objective-c uistoryboard

我需要能够在每个布尔选择的应用程序启动时选择具有初始UIViewController的故事板。每个故事板都可以...每个.plist(原始)设置。

所以我在应用程序的plist中删除了默认的初始故事板条目;并试图手动完成。

我得到的是我的设备上的黑屏。
变量' storyboard',' controller',' window'都是非零的。但我没有屏幕。为什么?

这是代码:

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UIColor *blissRed = [UIColor colorWithRed:228.0/255.0 green:0.0 blue:27.0/255.0 alpha:1.0];

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

    BOOL introStoryboard = YES;  // ...artificial condition for discussion.

    UIStoryboard *storyboard;
    UIViewController *controller;

    if (introStoryboard) {
        storyboard = [UIStoryboard storyboardWithName:@"Intro" bundle:nil];
        controller = [storyboard instantiateViewControllerWithIdentifier:kIntroStoryboardBeginning];
    } else {
        storyboard = [UIStoryboard storyboardWithName:@"Bliss" bundle:nil];
        controller = [storyboard instantiateViewControllerWithIdentifier:kBlissStoryboardBeginning];
    }

    [self.window setRootViewController:controller];

    return YES;
}


@end

2 个答案:

答案 0 :(得分:1)

你在回归之前忘了以下一行

[self.window makeKeyAndVisible];

答案 1 :(得分:0)

我曾经遇到过这种情况。我通过做 -

解决了这个问题
[navigationController pushViewController:controller animated:YES];

所以你需要做的是 -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UIColor *blissRed = [UIColor colorWithRed:228.0/255.0 green:0.0 blue:27.0/255.0 alpha:1.0];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.tintColor = blissRed;

    BOOL introStoryboard = YES;  // ...artificial condition for discussion.

    UIStoryboard *storyboard;
    UIViewController *controller;
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;

    if (introStoryboard) {
        storyboard = [UIStoryboard storyboardWithName:@"Intro" bundle:nil];
        controller = [storyboard instantiateViewControllerWithIdentifier:kIntroStoryboardBeginning];
} else {
        storyboard = [UIStoryboard storyboardWithName:@"Bliss" bundle:nil];
        controller = [storyboard instantiateViewControllerWithIdentifier:kBlissStoryboardBeginning];
}

   [navigationController pushViewController:controller animated:YES];

return YES;

}