【问题标题】:Switching from one navigation stack to another navigation stack using popViewController使用 popViewController 从一个导航堆栈切换到另一个导航堆栈
【发布时间】:2013-07-23 12:41:11
【问题描述】:

我创建了一个模块,其中有 5 个类,我需要执行类似的任务

vc1->vc2->vc3

现在从 vc3 开始,我曾经从基类的引用中推送 vc4。 基类是将 vc1 控制器添加为子视图的类。

现在我需要从 vc4 弹出到 vc3。

【问题讨论】:

  • 为什么不用三个Tab的Tabbarcontroller..?
  • 这个应用程序已经创建,我正在做一些改变,所以我不能改变应用程序的结构。

标签: iphone ios uinavigationcontroller popviewcontroller


【解决方案1】:
NSInteger index = 0;
for (UIViewController *view in self.navigationController.viewControllers) {
  if([view.nibName isEqualToString:@"YourViewController"])//put any `XIB name` where u want to navigate 
  break;
index = index + 1;
}
 //[[self navigationController] pushViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES];

[[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES];    

【讨论】:

  • 它不起作用,请自己尝试一下,我已经这样做了,因为您不会在导航堆栈中获得视图控制器,因为会有 2 个导航堆栈
【解决方案2】:
NSArray *array = [self.navigationController viewControllers];

[self.navigationController popToViewController:[array objectAtIndex:2] animated:YES];

获取要弹出的视图控制器的索引。

请参考这些链接:-

Can i pop to Specific ViewController?

pop a specific view controller

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-08
    • 2020-07-27
    • 2021-09-02
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多