swift 3准备(for segue :)功能坏了吗? [英] swift 3 prepare(for segue: ) function broken?

查看:142
本文介绍了swift 3准备(for segue :)功能坏了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于一些奇怪的原因,使用swift 3, prepare(对于segue:方法拒绝确认segue标识符。我将以下IBAction连接到一个按钮上UI:

for some odd reason , with swift 3, the prepare(for segue: method refuses to acknowledge the segue identifier. I have the following IBAction's connected to a couple button's on the UI:

@IBAction func goToImagesPicker(_ sender: AnyObject) {
    performSegue(withIdentifier: "showImagePicker", sender: sender)

}

@IBAction func goToNamePicker(_ sender: AnyObject) {
    performSegue(withIdentifier: "showNamePicker", sender: sender)
}

然而在我的 prepare(对于segue:方法,它不识别不同的segue标识符,我知道是因为我的控制台没有记录我分配给每个的消息:

However in my prepare(for segue: method, it doesn't recognize the different segue identifier's, I know so because my console doesn't log the messages I assigned to each:

func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "showImagePicker" {

            print("This is the Image Picker")

        }

        if segue.identifier == "showNamePicker"  {

            print("This is the Name Picker")

        } 
}

有什么建议吗?或者这只是一个错误?

any suggestions? or is this just a bug?

推荐答案

您的方法根本没有被调用,因为您的签名错误。它在Xcode 8 beta 6中更改为:

Your method isn't getting called at all because you have the wrong signature. It was changed in Xcode 8 beta 6 to:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

请注意发件人的类型是任何?而不是 AnyObject?。在升级Xcode之后你应该有一个错误,它告诉你你的方法没有覆盖其超类中的任何方法,它应该在你删除覆盖之前使用了。

Note that the type of sender is Any? instead of AnyObject?. You should have had an error after upgrading Xcode which told you your method wasn't overriding any method from its superclass which should have clued you in before you deleted the override.

这篇关于swift 3准备(for segue :)功能坏了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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