Guys in my app I have some code in the app delegate method application:didFinishLaunchingWithOptions:
that determines if the initial View Controller should be the LoginViewController
or the MainViewController
.
If the LoginViewController
is showed first and the user logs in successfully I show the MainViewController
modally with this piece of code:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
FSMainViewController *vc = (MainViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"MainViewController"];
vc.loginViewController = self;
[self presentViewController:vc animated:YES completion:nil];
What I want to do next, after the MainController
is showed on the screen, is remove the LoginViewController
from memory so in the viewWillApper:animated:
method of the MainViewController
I use this code to remove (or at least try to) the LoginViewController
:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (self.loginViewController) {
[self.loginViewController dismissViewControllerAnimated:NO completion:nil];
}
}
Problem is that this code leads to strange behaviors like the MainViewController
being removed from the screen and this error message showing up in the console.
Unbalanced calls to begin/end appearance transitions for <LoginViewController: 0xb06e350>
I also tried calling [self dismissViewControllerAnimated:NO completion:nil]
in the completion block of the presentViewController:animated:completion
method but still no luck, it didn't work.
What am I doing wrong? How can I remove from memory the underlying LoginViewController
when the MainViewController
is presented modally?