In the past my app has had only 1 main view controller (MainViewController
) and a login view controller (LoginViewController
) but now I am moving to a Tab Bar Controller.
Before I was able to do a simple check viewDidLoad
of MainViewController
for the existence of a username and password in the key chain. If a username and password was not present I used a segue to pop up a modal login view controller.
With the new setup of using a Tab Bar Controller I still only have 1 view controller (MainViewController
) which is the root view controller (as of now) and I am trying to do the same thing where it pops up modal of the login screen.
Now when I call the segue in the viewDidLoad
of MainViewController
:
[self performSegueWithIdentifier:@"loadLoginView" sender:nil];
I am getting this error:
Warning: Attempt to present <LoginViewController: 0x1757cd80> on <UITabBarController: 0x17571e50> whose view is not in the window hierarchy!
But if I associate a button to a method that loads the LoginViewController
by way of a segue it works fine. I am doing that in the MainViewController
like this:
-(void)loadLogin
{
[self performSegueWithIdentifier:@"loadLoginView" sender:nil];
}
I can see from the error message that when I try to perform the segue from the viewDidLoad
of MainViewController
it's trying to load the LoginViewController
from UITabBarController
.
Why can I not load the LoginViewController
from the viewDidLoad
of MainViewController
?
Any help with this would be great.
Thanks!