Kazunari
Kazunari

Reputation: 278

Warning “attempt to present ViewController whose view is not in the window hierarchy - Objective C

I'm trying to call a controller, if has response error, and redirect the user for login controller.

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"EventManagerStoryboard" bundle:[NSBundle mainBundle]];
LoginViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"loginID"];
[loginController viewDidLoad];
loginController.showOnlyLoginForm = YES;

[self presentViewController:loginController animated:YES completion:Nil];

and I facing this warning -

Attempt to present Attempt to present LoginViewController: 0x7fc958201130 on ProfileController: 0x7fc9583118e0 whose view is not in the window hierarchy!

Upvotes: 0

Views: 73

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100541

Don't run this code in viewDidLoad try it in viewDidAppear

 [self presentViewController:loginController animated:YES completion:Nil];

Edit:

use in appDelegate if you implement navigationController

 [(UINavigationController *)self.window.rootViewController pushViewController:vc animated:YES];

Upvotes: 1

Related Questions