swift 3 prepare(for segue: ) function broken? [duplicate]

巧了我就是萌 提交于 2019-12-03 05:43:49

问题


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)
}

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?


回答1:


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?) {

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.



来源:https://stackoverflow.com/questions/39563828/swift-3-preparefor-segue-function-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!