如何以编程方式退回到2个不同的VC

编程入门 行业动态 更新时间:2024-10-07 21:34:11
本文介绍了如何以编程方式退回到2个不同的VC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果您遇到三个ViewController的情况.黄色,绿色和白色.

If we have a situation where you have three ViewControllers. Yellow, green and white one.

您可以同时通过黄色和绿色获得白色.参见图片以获取更多说明:

You can get to the white one through both yellow and green one. See the picture for more clarification:

当我从黄色选为白色时,我准备进行搜索并将NSUinteger jimmy_hendrix值设置为0;

When I segue from yellow to white, I prepare for segue and set a NSUinteger jimmy_hendrix value to 0;

当我从绿色选为白色时,我准备进行选战并将NSUinteger jimmy_hendrix值设置为1;

When I segue from green to white, I prepare for segue and set a NSUinteger jimmy_hendrix value to 1;

在白色VC内,我制作了IBAction并将一个BACK按钮连接到它.在其中,根据值,我想平息我最终在白色VC中使用的segue.

Inside the white VC, I made IBAction and connected a BACK button to it. In there, depending on the value I want to unwind the segue which I ended up in the white VC.

这是我使用的代码:

- (IBAction)goBack:(UIButton *)sender { switch (_jimmy_hendrix) { case 0: [self performSegueWithIdentifier:@"fromYellowToWhite" sender:self]; break; case 1: [self performSegueWithIdentifier:@"fromGreenToWhite" sender:self]; break; } }

但是,我得到一个例外:

But, I get an exception :

'Receiver (<WhiteVC: 0x15d8c850>) has no segue with identifier 'fromSuperTraenerToSuperTraenerQuestions

为清楚起见,我从不按ctrl键并从后退"按钮拖动以退出,然后选择unwind segue方法,因为我要根据我使用的VC和segue进行两次取消操作.

To make this clear, I never ctrl + dragged from the BACK button to exit and then selected the unwind segue method, because there are two unwinds I want to perform, based on which VC and which segue I used.

对此有什么解决方案? 如何选择回到我最初使用的任何ViewvController?

What is a solution to this? How to segue back to whichever ViewvController I used to get to my destionation on the first place?

重要提示:我知道我可以进行新的选择,从白色到黄色和绿色,然后将其命名.但是我不想那样.我不想做新的任务,我想以编程的方式放松现有的任务.

IMPORTANT: I know I can make new segues, from white to yellow and green and call them. But I don't want that..I don't want to make new segues, I want to programatically unwind the existing ones.

我忘了提到我确实在绿色和黄色VC中制作了展开方法

I forgot to mention that indeed I made unwind methods in green and yellow VC

-(IBAction)fromYellowToWhite:(UIStoryboardSegue *)segue { } -(IBAction)fromGreenToWhite:(UIStoryboardSegue *)segue { }

推荐答案

您需要创建展开序列.在YellowVC中创建方法

You need to create the unwind segues. In YellowVC create a method

-(IBAction)fromYellowToWhite:(UIStoryboardSegue *)segue { }

并在GreenVC中创建一个方法

and in GreenVC create a method

-(IBAction)fromGreenToWhite:(UIStoryboardSegue *)segue { }

然后从White中的UIViewController实例拖动到White场景中的退出"图标,然后选择fromYellowToWhite.重复此操作,然后选择fromGreenToWhite:

Then drag from the UIViewController instance in White to the "exit" icon in the White scene and select fromYellowToWhite. Repeat this and select fromGreenToWhite:

最后,选择您新创建的Unse Segues,并将标识符设置为"fromYellowToWhite"和"fromGreenToWhite"-它们应具有"fromYellowToWhite:"和"fromGreenToWhite:"的操作"

Finally, select your newly created unwind Segues and set the identifiers to "fromYellowToWhite" and "fromGreenToWhite" - they should have an 'action' of "fromYellowToWhite:" and "fromGreenToWhite:"

更多推荐

如何以编程方式退回到2个不同的VC

本文发布于:2023-11-28 04:14:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640913.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   VC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!