How do I present a modal view at application startup?

一世执手 提交于 2019-12-12 04:59:53

问题


I have the following code in application didFinishLaunchingWithOptions where I want to present a modal view controller for user login.

LoginViewController_iPhone *loginViewController=[[LoginViewController_iPhone alloc]initWithNibName:@"LoginViewController_iPhone" bundle:nil];
UINavigationController *loginNavigationController=[[UINavigationController alloc]initWithRootViewController:loginViewController];
loginNavigationController.modalPresentationStyle=UIModalPresentationFullScreen;
[self.window.rootViewController presentModalViewController:loginNavigationController animated:NO];

[loginViewController release];
[loginNavigationController release];

However, all I get is a blank white screen. If I substitute the following

self.window.rootViewController=loginNavigationController;

the login screen displays correctly. There is no other view controller assigned to the rootViewController property as the app is just starting. Do I need another view controller assigned to get this to work?


回答1:


Yes. you need to assign something to the window's rootViewController property in order to call its method presentModalViewController.




回答2:


UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:LoginViewController];

navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:NO];

You can set this up in the viewDidLoad of the view that would load up first as soon as the app starts. So, as soon as login is successful, you can pop it off, and you will have the loaded view ready.



来源:https://stackoverflow.com/questions/6751021/how-do-i-present-a-modal-view-at-application-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!