0

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?

Ryan
  • 16,626
  • 2
  • 23
  • 20
ChrisP
  • 9,796
  • 21
  • 77
  • 121

2 Answers2

3

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

Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56
0
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.

Legolas
  • 12,145
  • 12
  • 79
  • 132
  • While this approach would work I chose the first answer as a callback via a delegate to the AppDelegate gives me more control after login. – ChrisP Jul 19 '11 at 17:35