通过 UINavigationViewController 在同级视图之间切换 [英] Switching between sibling views via UINavigationViewController

查看:20
本文介绍了通过 UINavigationViewController 在同级视图之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NavigationViewController 在主视图和详细视图之间导航.现在我希望能够在不首先显示主视图的情况下切换到同级详细视图,我已经尝试在相同的方法中执行 popViewController 和 pushViewController 或在详细视图中执行 popViewController ,然后在 popViewController 之后在 mater 的 viewDidLoad 中执行 pushViewController 但它不会工作 - 视图最终会返回到主视图而不切换到细节.知道该怎么做吗?

I am using a NavigationViewController to navigate between master view and detailed views. Now I want to be able to switch to a sibling detail view without first showing the master view and I have tried doing popViewController and pushViewController in the same method or popViewController in the detailed view and then pushViewController in mater's viewDidLoad after popViewController but it won't work - the view just ends up going back to the master view without switching to the detail. Any idea what to do?

据我所知,这里建议的解决方案不起作用:切换内容视图问题

The solution suggested here doesn't work as far as I can tell: Switching Content Views Issue

推荐答案

我从未尝试过,但这应该可行:

I've never tried it, but this should work:

// create instance of new view controller
MyViewController *myViewController = [[MyViewController alloc] init];

// get current stack of viewControllers from navigation controller
NSMutableArray *viewControllers = [[self.navigationController viewControllers] mutableCopy];

// replace top view controller in stack
[viewControllers replaceObjectAtIndex:([viewControllers count] - 1) withObject:myViewController];

// set modified stack of view controllers in navigation controller
[self.navigationController setViewControllers:viewControllers animated:YES];

根据文档,您的应用程序将通过推送动画过渡到新的视图控制器,然后当单击后退按钮时,它就像您推送的视图控制器从未存在过一样.(如果您不想要动画,请使用 animated:NO)

According to the docs, your app will transition to the new view controller with a push animation, and then when back button is clicked it it will be as if the view controller you pushed from was never there. (If you don't want the animation, use animated:NO)

这篇关于通过 UINavigationViewController 在同级视图之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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