如何从 navigationController(viewControllers/stack) 弹回指定 viewCon

2023-06-11移动开发问题
1

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

问题描述

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

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];

但是,这不是一个好的解决方案.因为这个方法需要你获取我们的B"所在的索引.

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

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

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

UIViewControllers 中的格式应为:
"< A: 0x6e70710 >","","< B: 0x6988a70 >","",""

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

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

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

推荐答案

这里我想知道NavigationController通过Concept Of Stack管理ViewController.ie LAST COME FIRST OUT.这里有两种相同的方法.

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)在这里您可以进行迭代以获得所需的 ViewController,如下所示

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) 这里有 A,B,C,D 控制器.意味着 B 将在第三位,所以你能做什么

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];

希望对你有所帮助..

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

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9

如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)...
2024-08-12 移动开发问题
13