Calling popViewControllerAnimated twice

前端 未结 4 1376
臣服心动
臣服心动 2021-01-30 11:26

I\'ve got a UINavigationController with a series of UIViewControllers on it. Under some circumstances, I want to pop back exactly two levels. I thoug

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 12:02

    I think its better to count the number of view controllers in you stack and then subtract the number of view controllers you would like to pop.

     NSInteger noOfViewControllers = [self.navigationController.viewControllers count];
     [self.navigationController 
     popToViewController:[self.navigationController.viewControllers 
     objectAtIndex:(noOfViewControllers-2)] animated:YES];
    

    With this solution you wont mess up the pop if you add a new view to your project later.

提交回复
热议问题