Calling [UINavigationController pushViewController:animated:] is no-ops and it will trigger another pushViewController

71 Views Asked by At

I am currently working on the following situation, i need to push two viewController (A and B) in sequence in short time.

So this is what i do.

  1. First call, [UINavigationController pushViewController:vcA animated:yes]
  2. In [navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated], i call [UINavigationController pushViewController:vcB animated:yes]

Since i have overrides some of functions in [UINavigationController pushViewController:animated], i want [UINavigationController pushViewController:animated] only triggered twice, one when pushing vcA and one when pushing vcB.

However, the current situation is that [UINavigationController pushViewController:animated] will be triggered for three times:

  1. First time when we call [UINavigationController pushViewController:vcA animated:yes]
  2. Second time when we call [UINavigationController pushViewController:vcB animated:yes]. However, this is strange because at this point, this is not doing anything. I checked NavigationController.viewControllers and find that vcB did not get pushed
  3. Third time, [UINavigationController pushViewController:vcB animated:yes] is triggered again, and it is triggered by [_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:], the full stacktrace can be seen here

So my question is, where did the third [UINavigationController pushViewController:vcB animated:yes] come from? I am certain that i did not override any _UIViewControllerTransitionCoordinator.

1

There are 1 best solutions below

0
king wang On

If you really want to do this (not a best practice)

Try this code:

navigationController?.pushViewController(vcA, animated: false)
navigationController?.pushViewController(vcB, animated: true)