Xcode 6 Storyboard Unwind Segue与Swift没有连接到退出 [英] Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit

查看:163
本文介绍了Xcode 6 Storyboard Unwind Segue与Swift没有连接到退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试将导航栏按钮连接到Xcode 6中的ViewController的Exit项目时(不确定它是否是Xcode 6问题但值得一提,因为它处于测试阶段)它没有在自定义中找到Swift功能class。

When trying to connect a Navigation Bar Button to the Exit item of a ViewController in Xcode 6 (not really sure if it's an Xcode 6 problem but worth mentioning as it is in beta) it does not find the Swift function in the custom class.

它应该找到的函数:

@IBAction func unwindToList(segue: UIStoryboardSegue) {

}

我在视图上做了另一个按钮确保我可以让一个IBAction与Swift一起工作并且我正确地编写它。这很好用:

I made another button on the view just to make sure I could get an IBAction working with Swift and that I was writing it correctly. This works fine:

@IBAction func test(sender: AnyObject) {

    NSLog("Test")
}

我见过这个问题似乎是同一个问题,但根据答案,这应该有效。

I have seen this question that seems like the same issue but according to the answers there this should be working.

Xcode 6处于测试阶段,当然,Swift非常新,但是想看看是否有人在考虑它之前遇到了这个问题。

Xcode 6 is in beta and, of course, Swift is very new, but wanted to see if anyone has come across this before considering it a potential bug.

推荐答案

这是Xcode 6的一个已知问题:

This is a known issue with Xcode 6:


接口生成器无法识别在Swift类中声明的展开segue操作

Unwind segue actions declared in Swift classes are not recognized by Interface Builder

为了绕过它,你需要它至:

In order to get around it you need to:


  1. 类MyViewController 更改为 @objc( MyViewController)类MyViewController

  2. 创建一个Objective-C头文件,其中包含重新声明segue操作的MyViewController类别。

  1. Change class MyViewController to @objc(MyViewController) class MyViewController
  2. Create an Objective-C header file with a category for MyViewController that redeclares the segue action.

@interface MyViewController (Workaround)
- (IBAction)unwindToMyViewController: (UIStoryboardSegue *)segue;
@end


  • 在故事板中,选择MyViewController的实例,清除它自定义类,然后
    将其设置回MyViewController。

  • In the storyboard, select the instance of MyViewController, clear its custom class, then set it back to MyViewController.

    执行这些步骤后,您可以连接按钮再次退出项目。

    After these steps you are able to connect buttons to the exit item again.

    Xcode 6发行说明 PDF,第10页

    这篇关于Xcode 6 Storyboard Unwind Segue与Swift没有连接到退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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