【发布时间】:2020-04-08 21:44:55
【问题描述】:
我需要根据表视图中的 if 结果创建两个“帮助”数组。 我的主要问题是:如何在另一个视图控制器中使用这个数组?
等:因为当我想通过 TableViewController().helpArrayOne 在另一个控制器中使用一个数组时,它在 tableViewController 中为空/或不存在,但在 tableViewController 中打印后我得到了值,谢谢。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell
let listOfStudents = allUrl.reduce(into: [String:String]()){$0[$1.id] = $1.stringValue}
for key in listOfStudents{
// Compare data
if cell.textLabel?.text == key.key {
cell.imageView!.image = UIImage(named:"false_icon")
var helpArrayOne:[String] = []
helpArrayOne.append(all[indexPath.row].id)
var helpArrayTwo:[String] = []
helpArrayTwo.append(all[indexPath.row].stringValue)
break
} else {
cell.imageView!.image = UIImage(named:"true_icon")
}
}
print(helpArrayOne,helpArrayTwo)
return cell
}
【问题讨论】:
标签: arrays swift if-statement tableview