[英]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开始,然后:
self.dismiss
, your using your exit segue. self.dismiss
,使用出口segue。 self.dismiss
or you can come back to A using the exit segue. 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.