简体   繁体   English

我如何选择另一个与当前根控制器共享相同根控制器的viewController?

[英]How do I segue to another viewController that shares the same root controller as the current one?

I have 3 viewControllers : A, B and C. 我有3个viewControllers :A,B和C。
A has a segue to B and A also has a segue to C. A对B有关系,A对C也有关系。

If I'm currently in C, how do I segue over to B? 如果我目前在C中,该如何选择B?

Note; 注意; I need to keep A active because once I'm in B, I need to be able to unwind back to A. 我需要保持A活跃,因为一旦进入B,我就需要能够退回到A。

The following solution would be nice if I could unwind from C to A and then push to B without showing A in the process, but I can't get this to work, and no-one has provided a solution. 如果我可以从C放松到A,然后在不显示A的情况下将其推到B,则以下解决方案将是不错的选择,但是我无法使其正常工作,而且没有人提供解决方案。

Chain two segues to look like one 将两个segue链接起来看起来像一个

Note; 注意; I'm not using a UINavigationController . 我没有使用UINavigationController I've tried simply pushing from C to B but then I'm not able to deallocate C. Calling unwind on C at any point during this process gives weird behaviour where A might appear on screen at some point. 我尝试过简单地从C推到B,但是我无法取消分配C。在此过程中的任何时候调用C的unwind都会产生奇怪的行为,其中A可能会出现在屏幕上。

Does anyone have a solution to this? 有人对此有解决方案吗?

There is plenty of way to accomplish what you want. 有很多方法可以完成您想要的。

I would do something really easy: that is to add an unwind segue (it's explained above how to add one) to exit to the first A vc, and add a custom segue (no matter which one) between B and C (that you simply create with the storyboard). 我会做一些非常简单的事情:添加一个放松的序列 (上面已经解释了如何添加一个序列 )以退出到第一个A vc,并在B和C之间添加一个自定义序列 (无论是哪个序列 )(您只需使用情节提要创建)。

You start in A, then: 您从A开始,然后:

  • If you go to B, you can come back using the self.dismiss , your using your exit segue. 如果您前往B,则可以使用self.dismiss ,使用出口segue。
  • If you go to C, you can come back to A the same way, or you can go to B. 如果转到C,则可以以相同的方式返回A,也可以转到B。
  • Once you are in B (from: A to C, C to B), you can come back to C using self.dismiss or you can come back to A using the exit segue. 进入B后(从A到C,从C到B),您可以使用self.dismiss返回C,也可以使用出口segue返回A。

To add un unwind segue, you must add a function to your first VC of the type: 要添加解散序列,必须将函数添加到类型的第一个VC中:

@IBAction func unwindToA(segue: UIStoryboardSegue)

Then, in the storyboard when you are creating your segue on the your B view controller (using control+drag), start to drag from the VC icon (on the top of the screen) to the exit icon. 然后,在情节提要中,当您在B视图控制器上创建Segue时(使用Control + Drag),开始从VC图标(在屏幕顶部)拖动到退出图标。 Then, you will see appear a new segue, named 'unwindToA', which will take you back to your first VC: A. 然后,您会看到一个名为“ unwindToA”的新名称,它将带您回到第一个VC:A。

您可以在此处(屏幕顶部)看到这些图标

To create your segue from B to C, you can do by control+drag from the first to the second VC in your storyboard, and choose the type you prefer (or you can create a custom segue if those provided don't correspond to want you expect). 要从B到C创建序列,您可以通过控制+拖动故事板中的第一个VC至第二个VC,然后选择您喜欢的类型(或者您可以创建自定义序列,如果提供的序列与想要的序列不符)。您期望)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在一个标签栏控制器中从一个ViewController切换到另一个ViewController? - Segue from one ViewController to another ViewController inside a Tab Bar Controller? 如何通过AlertView切换到另一个ViewController? - How do I switch to another ViewController with perform segue via AlertView? 如何从一个视图控制器转移到另一个视图控制器 - How to segue from one viewcontroller to another 如何在标签栏控制器中从一个视图控制器切换到另一个视图控制器并保留标签栏? - How within a tab bar controller do I segue from one view controller to another and retain the tab bar? 如何在另一个 TabController 中选择 ViewController? - How can I segue to a ViewController in another TabController? 如何找到属于当前viewController的导航控制器? - How do I find out the navigation controller that is part of the current viewController? 5秒后如何自动从一个ViewController切换到另一个ViewController - How to automatically segue from one viewcontroller to another after 5 secs viewcontroller-如何获取另一个根视图控制器/如何切换视图 - viewcontroller - how to get another root view controller / how to switch Views 如何同时进行模态搜索和弹出到导航控制器的根目录? - How to do a modal segue and pop to root in navigation controller simultaneously? 如何从情节提要中的NIB子视图选择视图控制器 - How do I segue from a NIB subview to a viewcontroller in the storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM