在啟動時候有三個視圖,想要實現的是可以根據設備類型來選擇三個中的一個。目前我寫的代碼在AppDelegate.m
中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// 應用啟動後重寫制定
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_Portrait5" bundle:nil];
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 480.0) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_Portrait4" bundle:nil];
}
else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_PortraitPad" bundle:nil];
}
}
但是運行之後,應用啟動的時候屏幕一片漆黑。
怎麼解決,謝謝。
在方法的最後添加:
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];