Harish
Harish

Reputation: 2512

Obj C - Present view controllers one after another

It may be simple, but i'm scratching my head to find out the issue.

I'm presenting a UINavigationController and once it's dismissed I need to present another one which is a UITabBarController, when I do that I get below error

Warning: Attempt to present < MyTabBarViewController: 0xXXXX > on < ParentViewController: 0XXX> whose view is not in the window hierarchy!

UINavigationController *nav = [self.storyboard instantiateViewControllerWithIdentifier:@"myWeb"];
MyWebViewController *webVC = (MyWebViewController *)nav.topViewController;
[self presentViewController:webVC animated:YES completion:nil];

I can see MyWebViewController is presented without any issue, once the previous one is dismissed, I try to present next one like below, I'm getting the above warning.

MyTabBarViewController *trController = [[MyTabBarViewController alloc] init];
[self presentViewController:trController animated:NO completion:nil];

Upvotes: 0

Views: 264

Answers (1)

Ponja
Ponja

Reputation: 663

You need to present MyTabBarViewController only when the MyWebViewController has finished dismissing, try adding a delay like this:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    MyTabBarViewController *trController = [[MyTabBarViewController alloc] init];
    [self presentViewController:trController animated:NO completion:nil];
});

if this works, you will need to get rid of that (in case you want to keep your code clean) and call a delegate method inside completion telling the parent that the MyTabBarViewController is ready to be presented.

Upvotes: 1

Related Questions