【发布时间】:2016-06-19 12:21:20
【问题描述】:
我正在制作一个应用程序,当你按下一个按钮说它很紧急时,会有一个标签显示“紧急”。就在我实现与按钮的用户交互之前,我有一个数组(如下所示),其中一些对象具有urgent = true,但有些对象具有urgent = false,因此我可以从我的代码开始。
数组,在MainTableViewController.swift:
var content:[Agenda] = [
Agenda(subject: "Read this article", deadline: "1-2 days", urgent: false),
Agenda(subject: "Respond to this email", deadline: "ASAP", urgent: true),
Agenda(subject: "Add this to diary", deadline: "When at home", urgent: true),
Agenda(subject: "Listen to this song", deadline: "When finished working", urgent: false),
Agenda(subject: "Check out this holiday destination", deadline: "At the weekend", urgent: false),
Agenda(subject: "Download this podcast", deadline: "1-4 days", urgent: false),
Agenda(subject: "Update notes", deadline: "When at home", urgent: true)
]
然后,我有一个名为 Agenda.swift 的类,我在其中声明了 subject、deadline 和 urgent。
这是我是否显示“紧急”的代码:
if content[indexPath.row].urgent = true {
cell.urgentLabel.text = "URGENT"
} else {
cell.urgentLabel.text = ""
}
在第一行,我收到以下错误:
不能为“inout [Agenda]”(又名“inout Array”)类型的值下标
【问题讨论】:
-
if content[indexPath.row].urgent = true {应该只是if content[indexPath.row].urgent { -
或 == 而不是 =(赋值语句在 Swift 中不返回任何内容)
-
@VinceBurn 谢谢 :)
标签: ios arrays swift uitableview