我想在应用程序窗口调用-makeKeyAndVisible
之前以模态方式呈现视图控制器。但是,此代码仅显示mainNav
视图控制器:
- (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;
}
我错过了什么?
答案 0 :(得分:3)
您最好让窗口显示,然后使用animated=NO
显示模式视图。在其他所有实例化和显示之前呈现模态视图有什么意义?
为了使您的代码有效,这里有几个提示。试试这个:
[mainNav presentModalViewController:learnNav animated:NO];
或者这个:
[main.navigationController presentModalViewController:learnNav animated:NO];
我认为如果将这两种方法放在makeKeyAndVisible
电话之后,这两种方法效果最佳。