如何从多个导航控制器切换到一个视图控制器,完成后返回到快速呈现的任何视图控制器 [英] How to segue to one view controller from multiple navigation controllers and when done go back to whichever view controller presented it swift

查看:24
本文介绍了如何从多个导航控制器切换到一个视图控制器,完成后返回到快速呈现的任何视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有两个导航控制器层次结构,它们都指向一个视图控制器.我传递了一个视图控制器数据,该数据基于哪个视图控制器数据通过推送转场呈现给它.如何关闭最终的视图控制器并返回到呈现它的导航堆栈?我不需要回传任何信息,但是当我尝试执行 unwind segue 时,我收到一条错误消息,指出此类不符合键 doneButtonTapped 的键值编码",我尝试了 unWind segue 和 popVC segue.

So I have two navigation controller hierarchies that both lead to one view controller. I pass that one view controller data based on which one presented it with a push segue. How do I dismiss the final view controller and go back to the navigation stack that presented it? I don't need to pass any info back, but when I tried to do an unwind segue I was getting an error stating "this class is not key value coding-compliant for the key doneButtonTapped" I tried unWind segue and popVC segue.

我相信问题可能在于您不能有两个单独的导航堆栈通向一个视图控制器,因为该视图控制器不知道它属于哪个堆栈.我尝试过研究,但只能找到如何同时关闭多个模态视图,而不是关闭一个 VC 当时向哪个 VC 展示它.

I believe the problem might be that you can't have two separated navigation stacks leading to one view controller because that view controller doesn't know which stack it is a part of. I tried researching but could only find how to dismiss multiple modal views at once, nothing about dismissing one VC to which ever VC presented it at the time.

谢谢

推荐答案

你只需要调用 popViewController 来关闭 viewcontroller.它将自动跟随由导航控制器 A 或 B 创建的导航堆栈.

You just need to call popViewController to dissmiss viewcontroller. It will automatically follow navigation stack which was created by navigationcontroller A or B.

如果你想弹出第一个viewcontroler,那么可以调用popToRootViewController.

If you want to pop to first viewcontroler then can call popToRootViewController.

希望这会有所帮助:)

这篇关于如何从多个导航控制器切换到一个视图控制器,完成后返回到快速呈现的任何视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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