【发布时间】:2016-05-04 13:06:03
【问题描述】:
我正在尝试将 ILTItem 变量传递到我的 ILTViewController,当用户通过深层链接启动我的应用程序时由 AppDelegate.swift 触发。
我有错误的代码:
不能调用非函数类型'String'的值
在我定义ilt的那一行。
这是我目前拥有的代码:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var ilt = ILT(homeworkID: 1234, title: "History ILT", subject: "History", teacher: "Miss A Smith", teacherCode: "asmith", studentID: 12345, description: "Description....", due: 1450137600, status: "In Progress", hasAttachments: true)
var newVC = ILTViewController()
newVC.ILTitem = ilt
appDelegate.window?.addSubview(newVC.view)
为什么会这样?在我的 ILTViewController 类中,我有:
class ILTViewController: UIViewController {
// accept the incoming ILT struct
var ILTitem: ILT!
IlT 结构声明:
struct ILT {
let homeworkID: Int
let title: String
let subject: String
let teacher: String
let teacherCode: String
let studentID: Int
let description: String
let due: Double
let status: String
let hasAttachments: Bool
}
【问题讨论】:
-
发布你的
ILT类声明 -
@redent84 我已经添加了
-
您的代码运行良好:swiftstub.com/580271845。您可能在其他地方声明了一个名为
ILT的String变量,这就是它失败的原因。 -
@redent84 这不是问题,因为当我将它合并到
newVC.ILTItem = ILT(homeworkID: 1234, title: "History ILT", subject: "History", teacher: "Miss A Smith", teacherCode: "asmith", studentID: 12345, description: "Description....", due: 1450137600, status: "In Progress", hasAttachments: true)时,它仍然会失败并显示相同的消息。 -
我的意思是你重新声明了
ILT(大写),而不是ilt(小写)。该错误告诉您您正在尝试调用String而不是方法(在您的情况下为结构构造函数)。而且,您可以查看我提供的链接,错误在您的代码中的其他地方,因为您发布的代码可以正常工作。
标签: ios swift struct viewcontroller