如何在没有 App Delegate 的 plist 的情况下手动 select 初始故事板?
How do I manually select an initial storyboard without the plist from the App Delegate?
我需要能够 select 每个布尔选择在应用程序启动时使用其初始 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
我曾经遇到过这种情况。我通过做 -
解决了它
[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;
}
您刚刚忘记了 return
之前的以下行
[self.window makeKeyAndVisible];
我需要能够 select 每个布尔选择在应用程序启动时使用其初始 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
我曾经遇到过这种情况。我通过做 -
解决了它[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;
}
您刚刚忘记了 return
之前的以下行[self.window makeKeyAndVisible];