在 Xcode 6 Beta 4 中解开 Segue [英] Unwind Segue in Xcode 6 Beta 4

查看:25
本文介绍了在 Xcode 6 Beta 4 中解开 Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试向 Xcode 6 中的 swift 应用程序添加 unwind segue,并且在前三个测试版的发行说明中,它被声明为不受支持.但是,在 Beta 4 中,该错误说明不再存在.我听说人们已经能够让它发挥作用,但我没有这样的运气.所以,我的问题是:我应该如何尝试查看 unwind segue 是否可以在我的应用程序中工作?我应该尝试什么?我正在使用 UIBarButtonItem 来触发 segue.

I've been trying to add an unwind segue to a swift app in Xcode 6, and, in the release notes for the first three betas, it was declared to be unsupported. However, in Beta 4, that bug note is no longer present. I have heard that people have been able to get it to work, but I have had no such luck. So, my question is this: how should I try to see if the unwind segue will work in my app? What should I try? I am using a UIBarButtonItem to trigger the segue.

到目前为止,我已将此代码放在目标控制器的 .swift 文件中:

So far, I've put this code in the destination controller's .swift file:

@IBAction func unwindToSegue(segue:UIStoryboardSegue) {}

使用此代码,我能够通过从栏按钮控制拖动到退出图标,然后单击 unwindToSegue 方法将栏按钮连接到函数.这部分工作了,但代码没有运行,即使我在函数中放置了一个断点,它也没有被调用.

Using this code, I was able to connect the bar button to the function by control-dragging from the bar button to the exit icon, and then clicking the unwindToSegue method. That part has worked, but the code doesn't run, even when I put a breakpoint inside the function it wasn't called.

推荐答案

您需要将 unwindToSegue 函数放在原始 ViewController(即您尝试返回的 ViewController)中.

You need to put your unwindToSegue function in the originating ViewController (that is, the ViewController you are trying to return to).

您可以尝试的另一件事是以编程方式调用 segue.首先,将一个退出segue从视图控制器图标连接到退出图标(三个图标都在Interface Builder中视图控制器的顶部).为该转场命名,例如goBackHome".然后连接你的按钮来调用这个@IBAction:

Another thing you can try is to call the segue programmatically. First, wire an exit segue from the view controller icon to the exit icon (the three icons are all on the top of the view controller in Interface Builder). Give that segue a name such as "goBackHome". Then wire your button to call this @IBAction:

@IBAction func headHome() {
    println("Button seen.  Trigging exit segue manually...")
    self.performSegueWithIdentifier("goBackHome", sender: self)
}

这篇关于在 Xcode 6 Beta 4 中解开 Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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