ViewWillAppear and viewDidLoad to represent the login

I have a UIViewController in which it should pop up LoginViewController if the user is not already registered. The question is where should I call it:

LoginViewController* lvc = [[LoginViewController alloc] init]; lvc.delegate = self; //[lvc setModalPresentationStyle:UIModalPresentationFullScreen]; [self presentModalViewController:lvc animated:NO]; [lvc release]; 

should it be in viewDidLoad or in viewWillAppear? I think it makes sense to put it in viewWillAppear? I tried putting it in viewDidLoad, and that gives me an extra border to the left and right of the view. Why is this?

UPDATE:

What I'm trying to do here is call presentModalViewController on the DetailViewController for the UISplitViewApplication. However, nothing happens when I do this. I tried to create a new new UISplitViewApplication project, but still it did not work. The question is why? and how to present a modal view in a ViewAppear view UISplitViewApplication

+4
source share
2 answers

A modal window tries to initialize itself in relation to the view controller that called it (for example, resizing an element). Creating and displaying it in the parent viewDidLoad can sometimes give incorrect information, since the parent itself is still loading. That is why you see discrepancies. The representation of the modal controller in viewDidAppear better in this case, since all parameters are ready to go to the modular controller so that it can correctly load its own view. Although sometimes, if you need to load a lot, even this is not enough, and you will need to wait longer before you can present your modal view (which is completely different from your case, so there should not be anything that could worry there). Hope this helps though

0
source

I would post something like this in AppDelegate.

 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { [self.window addSubview:self.viewController.view]; [self.window makeKeyAndVisible]; // Show the login screen if the user hasn't logged in yet if (... login check here...) { LoginViewController* loginController = [[LoginViewController alloc] init]; [self.viewController presentModalViewController:loginController animated:NO]; [loginController release]; } } 

Your login screen will be placed on top of your regular view controller. After successful login, reject LoginViewController and your user can start using your application.

0
source

All Articles