How to present a modal representation at application launch?

I have the following code in a didFinishLaunchingWithOptions application 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 is displayed correctly. There is no other view controller assigned to the rootViewController property since the application is just starting. Do I need another view controller assigned for it to work?

0
source share
2 answers

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

+3
source
 UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:LoginViewController]; navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:navController animated:NO]; 

You can set this in the viewDidLoad of the view, which will be loaded first as soon as the application starts. So, as soon as the login is successful, you can turn it off, and you will have a finished download.

0
source

Source: https://habr.com/ru/post/910273/


All Articles