Problem pushing multiple view controllers onto navigation controller stack

后端 未结 2 1511
旧时难觅i
旧时难觅i 2020-12-15 21:39

I am trying to push three view controllers onto the navigation controller.

  [self.navigationController pushViewController:one animated:YES];
  [self.naviga         


        
相关标签:
2条回答
  • 2020-12-15 22:03

    For the first two pushes, don't pass the animated flag in as YES, set it to NO:

    [self.navigationController pushViewController:one animated: NO]; 
    [self.navigationController pushViewController:two animated: NO];
    [self.navigationController pushViewController:three animated: YES];
    

    This will give you the effect you want. Otherwise, you're confusing the animation system, as it tries to animate three views into the same space.

    0 讨论(0)
  • 2020-12-15 22:05

    The problem with the current most upvoted answer is that one and two will be visible in a split second before the third becomes visible. Not a huge problem, but it'll not make a good impression on the user. The solution you're looking for:

    NSMutableArray *controllers = [self.navigationController.viewControllers mutableCopy];
    [controllers addObject:one];
    [controllers addObject:two];
    [controllers addObject:three];
    [self.navigationController setViewControllers:controllers animated:YES];
    

    This will animate in three without one or two becoming visible in the process.

    0 讨论(0)
提交回复
热议问题