如何展开两个视图控制器 [英] How to unwind two view controllers

查看:38
本文介绍了如何展开两个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个视图控制器:

  • VC1
  • 包含childViewController(VC3)的VC2
  • VC4

这是工作流程:

  1. VC1显示(推送)VC2,同时也加载VC3.
  2. a.可以通过恢复正常运行回到VC1,这很正常.
  3. b.VC3有一些按钮可以显示(按下)VC4.
  4. VC4有一个可选列表.

我想将选定的行返回到VC1,所以我实现了一个unwind方法,以从VC4返回到VC2,然后在unwindToVC2方法中,我调用了另一个segue:

I want to go back with selected row to VC1, so I have implemented an unwind method to return from VC4 to VC2, and then, inside unwindToVC2 method, I am calling another segue:

[self performSegueWithIdentifier:@"returnToVC1"];

但是这种调用没有被调用或无法正常工作.

But this segue is not being called or it is not working.

尝试调试问题,该应用完全返回VC2,并调用了"returnToVC1" segue,但未发生任何事情,并且没有引发任何错误.

Trying to debug the problem, the app goes back perfectly to VC2, and it calls the "returnToVC1" segue but nothing ocurrs, and it doesn't throw any error.

在搜索修复程序时,我发现在显示的视图消失之前已调用unwind方法.是问题的原因吗?因为VC4仍然可见,所以无法撤消VC2吗?

Searching for a fix, I have found that unwind method is called before the presented view has disappear. Is it the cause of the problem? is it not possible to unwind VC2 because VC4 is still visible?

有什么办法可以让两个View Controller发送信息吗?

Is there any way to go back two View Controllers sending info?

谢谢

推荐答案

正如@rdelmar所说,我唯一要做的就是放松对VC1的控制.我来自Android,但由于VC2位于堆栈中其他VC的中间而无法实现.

As @rdelmar said, the only thing I have to do is an unwind segue to VC1. I came from Android and I though it was not possible because VC2 was in the middle of the others VC in the stack.

另一种方法(效果不如第一种方法)好​​于在viewDidAppear中执行VC2展开搜索,而不是展开方法.此修复程序有效,但是显示了第二个视图控制器一段时间.

Another solution, not working as fine as the first is to perform the VC2 unwind segue in viewDidAppear, instead of unwind method. This fix works but it shows the second view controller for a while.

问题的原因是当执行它的ViewController不可见时,不能调用performSegue.

The reason of the problem is that performSegue cannot be called when the ViewController which execute it is not visible.

感谢@rdelmar

Thanks @rdelmar

这篇关于如何展开两个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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