在Swift准备Segue [英] Prepare for Segue in Swift

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

问题描述

我正面临错误消息:

"UIStoryboardSegue does not have a member named 'identifier'"

以下是导致错误的代码

if (segue.identifier == "Load View") {
    // pass data to next view
}

在Obj-C上可以这样使用:

On Obj-C it's fine using like this:

if ([segue.identifier isEqualToString:@"Load View"]) {
   // pass data to next view
}

我做错了什么?

推荐答案

这似乎是由于 UITableViewController 子类模板。它附带了一个版本的 prepareForSegue 方法,需要你打开segue。

This seems to be due to a problem in the UITableViewController subclass template. It comes with a version of the prepareForSegue method that would require you to unwrap the segue.

替换你当前的 prepareForSegue 函数:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "Load View") {
        // pass data to next view
    }
}

此版本隐式展开参数,所以你应该没事。

This version implicitly unwraps the parameters, so you should be fine.

这篇关于在Swift准备Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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