如何弹出以从navigationController(viewControllers/stack)指定viewController? [英] How to pop back to specify viewController from navigationController(viewControllers/stack)?

查看:116
本文介绍了如何弹出以从navigationController(viewControllers/stack)指定viewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个具有串行视图(A,B,C,D等)的应用程序,我需要将D弹出回B. 有人可能会说为什么不使用:

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

但是,这不是一个好的解决方案.因为此方法需要您获取存储"B"的索引.

问题:如何在viewControllers中获取"B"的索引?

中的

格式应为:
< A:0x6e70710>", < C:0x6e30370>", < B:0x6988a70>", < D:0x6ea8950>", < E:0x6eaaad0>"

我尝试使用rangeOfStringhasPrefix来获取"B"视图的索引失败.

解决方案

在这里,我想了解一下NavigationController是通过Concept Of Stack .ie LAST COME FIRST OUT管理ViewController的.这里有两种方法可以做到相同. /p>

1)您可以在此处进行迭代,以获取所需的ViewController,如下所示:

  for (id controller in [self.navigationController viewControllers])
   {
   if ([controller isKindOfClass:[BViewController class]])
  {
    [self.navigationController popToViewController:controller animated:YES];
    break;
  }
  }

2)这里有A,B,C,D控制器.表示B将位于第三位置,那么您可以做什么

您可以按如下所示硬连接索引

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

希望对您有帮助.

I've created an application with serial views (A,B,C,D,...), and I need to pop back D to B. Someone may say Why not using:

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

However, it is not a good solution. Because this method needs you to get the index which our "B" is store in.

Question: How to get the index of "B" in the viewControllers?

format in the UIViewControllers should be:
"< A: 0x6e70710 >", "< C: 0x6e30370 >", "< B: 0x6988a70 >", "< D: 0x6ea8950 >", "< E: 0x6eaaad0 >"

I've tried and failed to use rangeOfString and hasPrefix to get the "B" view's index.

解决方案

Here i would like to know you that NavigationController manage the ViewController by the Concept Of Stack.ie LAST COME FIRST OUT.Here are two Approach for doing the Same.

1)Here you can make iteration for getting the desirable ViewController as Below

  for (id controller in [self.navigationController viewControllers])
   {
   if ([controller isKindOfClass:[BViewController class]])
  {
    [self.navigationController popToViewController:controller animated:YES];
    break;
  }
  }

2) Here you have A,B,C,D Controllers. means B would be on 3rd Position so what can you do

you can hard wired the Index as Below

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

I hope it may helpFull to you..

这篇关于如何弹出以从navigationController(viewControllers/stack)指定viewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆