开发者

How do I present a modal view at application startup?

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 contro开发者_如何学JAVAller assigned to the rootViewController property as the app is just starting. Do I need another view controller assigned to get this to work?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜