1

-makeKeyAndVisibleアプリケーションのウィンドウを呼び出す前に、View Controller をモーダルに表示したいと思います。ただし、このコードはmainNavView Controllerのみを示しています。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    MainViewController *main = [[MainViewController alloc] init];
    UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:main];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Restore"]) 
    {
        DetailViewController *detail = [[DetailViewController alloc] init];
        UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detail];

        // changing main to mainNav does not help
        [main presentModalViewController:learnNav animated:NO];

        [detailNav release]; [detail release];

    }

    self.window.rootViewController = mainNav;

    [main release]; [mainNav release];

    [self.window makeKeyAndVisible];

    return YES;
}

私は何が欠けていますか?

4

1 に答える 1

3

ウィンドウを表示してからモーダル ビューを で表示することをお勧めしますanimated=NO。他のすべてがインスタンス化されて表示される前に、モーダル ビューを表示するポイントは何ですか?

編集

コードを機能させるためのヒントをいくつか紹介します。これを試して:

[mainNav presentModalViewController:learnNav animated:NO];

またはこれ:

[main.navigationController presentModalViewController:learnNav animated:NO];

これら 2 つの方法は、呼び出しの後に配置すると最適に機能すると言えmakeKeyAndVisibleます。

于 2011-06-06T12:29:19.827 に答える