0

When I log in successfully with a third party and then jump to the UITabBarController, the viewWillAppear of the UITabBarController is always executed twice.

This is the code of jumpping to the UITabBarController. TTabBarVC inherited from UITabBarController.

TTabBarVC *vc = [TTabBarVC new];
KLNavigationController *nc = [[KLNavigationController alloc] initWithRootViewController:vc];
UIViewController *oldRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
[UIView transitionFromView:oldRootVC.view toView:nc.view duration:.3f options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
    [UIApplication sharedApplication].keyWindow.rootViewController = nc;
}];
rmaddy
  • 298,130
  • 40
  • 468
  • 517
代思思
  • 13
  • 5
  • What about the viewDidLoad? Is it called twice too? – Athul George Mar 05 '18 at 04:51
  • it is called one about the ViewDidLoad – 代思思 Mar 05 '18 at 06:25
  • I assume you meant viewDidLoad is called once. If that is so, i think there is some view which is active on top of the tabbar controller. Something like alert, popup or maybe aven a viewController. I suggest you go through the code again and verify. You code seems fine and does the job. I tried it and it does work. viewWillAppear is not being called twice. Try printing the window's view hierarchy when viewWillAppear is being called. – Athul George Mar 05 '18 at 06:35
  • How I print the window's view hierarchy when viewWillAppear is being called. – 代思思 Mar 05 '18 at 06:52
  • Put a breakpoint on viewWillAppear. Then check "Debug View Hierarchy" in Xcode. See [this answer](https://stackoverflow.com/questions/5150186/how-do-i-inspect-the-view-hierarchy-in-ios) – Athul George Mar 05 '18 at 12:21

0 Answers0