0

起動時に 3 つのビューのうちの 1 つを起動しようとしています。起動したいビューは、デバイスの種類によって異なります。ここに私がこれまでに持っているものがありますAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    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];
    }
}

問題は、アプリを起動すると黒い画面が表示されることです。

4

2 に答える 2

2

そのコードを書くためのはるかにクリーンな方法があります(修正を含む):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    NSString *nibName;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        nibName = @"ViewController_PortraitPad";
    } else {
        if ([UIScreen mainScreen].bounds.size.height == 480.0) {
            nibName = @"ViewController_Portrait4";
        } else {
            nibName = @"ViewController_Portrait5";
        }
    }

    self.viewController = [[ViewController alloc] initWithNibName:nibName bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
于 2012-12-08T16:43:02.853 に答える
2

ウィンドウにコントローラーを設定していないため、メソッドの最後に次を追加します。

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
于 2012-12-08T16:26:22.907 に答える