I tried to present a modal view controller on a view did load.
Here’s the code:
if (!self.loginNavViewController_){
AHLoginViewController * loginVC = [[AHLoginViewController alloc] initWithNibName:@"AHLoginViewController" bundle:nil];
/*
AHTestViewController * test = [[AHTestViewController alloc] initWithNibName:@"AHTestViewController" bundle:nil];
*/
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginVC];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
navController.title = @"Login to Instagram";
self.loginNavViewController_ = navController;
[self presentModalViewController:self.loginNavViewController_ animated:YES];
if (self.loginNavViewController_ == nil){
NSLog(@"NIL");
} else {
NSLog(@"NOT NIL");
}
}
However I don’t see a modal view controller being shown. Why??
A view controller receives
viewDidLoadimmediately after loading the view and before the view is inserted into a view hierarchy. In other words, it cannot present a modal view controller because its own view is not in any window yet.Try to do that in
viewWillAppear:orviewDidAppear:instead.