我希望创建一个包含多个故事板的应用程序,以支持iPhone5,iPhone4(及以下)和iPad屏幕。
我做了以下事情:
我输入以下代码到AppDelegate“didFinishLaunchingWithOptions”方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard* appStoryboard = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if (IS_IPHONE_5) //a macro capturing the screen size
{
appStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
}
else
{
appStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone4" bundle:nil];
}
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
appStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
}
UIViewController* viewController = [appStoryboard instantiateInitialViewController];
[self.window setRootViewController:viewController];
[self.window makeKeyAndVisible];
return YES;
}
应用程序正在运行但没有崩溃,但我得到了黑屏。
我错过了什么/做错了什么?
答案 0 :(得分:1)
您没有初始化window
。
添加
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];