iOS ߝ显示导航堆栈中已有的视图控制器
这可能很容易解决,但我无法弄清楚。我有一个带有两个选项卡的选项卡栏应用程序,每个选项卡都有一个 UINavigationController 。
假设我在选项卡 1 中推送一个名为 ItemViewController
的视图控制器,然后转到选项卡 2。我想从选项卡 2 以编程方式显示 ItemViewController
。因此,它应该首先将我带到选项卡 1,然后显示 ItemViewController
。
只需点击选项卡 1 选项卡项即可轻松实现此目的,但出于其他原因我想以编程方式执行此操作。
我现在正在做什么来实现这一目标:
[tab1NavController popToRootViewControllerAnimated:NO];
[tabBarController setSelectedIndex:0];
[tab1NavController pushViewController:itemViewController animated:NO];
我希望能够用伪代码做这样的事情:
if(viewControllerIWantToDisplayIsOnNavStack)
[tab1NavController presentViewController:viewControllerIWantToDisplay];
else
//instantiate and pushviewcontroller onto stack
我怎样才能实现这一目标?
This is probably easily sorted but I can't figure it out. I have a tab bar application with two tabs, each tab has a UINavigationController
.
Let's say that I in tab 1 push a viewcontroller called ItemViewController
, then I go to tab 2. From tab 2 I want to programatically display the ItemViewController
. So it should first take me to tab 1 and then display the ItemViewController
.
This is easily achievable by just tapping on the tab 1 tab item but I want to do this programtically for other reasons.
What I'm doing right now to achieve this:
[tab1NavController popToRootViewControllerAnimated:NO];
[tabBarController setSelectedIndex:0];
[tab1NavController pushViewController:itemViewController animated:NO];
I would like to be able to do something like this in pseudo-code:
if(viewControllerIWantToDisplayIsOnNavStack)
[tab1NavController presentViewController:viewControllerIWantToDisplay];
else
//instantiate and pushviewcontroller onto stack
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,您不必再弹出到选项卡 1 中的根视图控制器。
So you don't have to pop to root view controller in the tab 1 any more.
对我来说,以下方法有效,我使用循环来检查类是否在堆栈数组中
for me following way worked, i used loop to check if class is in stack array
以编程方式选择另一个选项卡非常容易,只需执行以下操作:
但我看到您已经知道这一点。您可以通过如下检查来检查堆栈上的顶部视图控制器是否是您需要的视图控制器类型:
it's very easy to programmatically select another tab, just do this:
But I see you already know this. You can check whether the top view controller on the stack is the type of viewcontroller you need by checking like this: