[英]Presenting Modal View Controller before window is visible
我想在應用程序的 window 上調用-makeKeyAndVisible
之前以模態方式呈現一個視圖 controller。 但是,此代碼僅顯示mainNav
視圖 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;
}
我錯過了什么?
您最好讓 window 出現,然后使用animated=NO
呈現模態視圖。 在實例化和顯示其他所有內容之前呈現模態視圖有什么意義?
為了嘗試使您的代碼正常工作,這里有一些提示。 嘗試這個:
[mainNav presentModalViewController:learnNav animated:NO];
或這個:
[main.navigationController presentModalViewController:learnNav animated:NO];
我想說這兩種方法如果放在makeKeyAndVisible
調用之后效果最好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.