【发布时间】:2018-02-25 09:14:33
【问题描述】:
所以我有一个使用核心数据的表格视图,当我选择一个单元格时,它会转到另一个 VC 并从对应于所选单元格的 CoreData 发送“目标”类项。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "toGoalPopup", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toGoalPopup" {
let destinationVC = segue.destination as! goalPopupViewController
if let indexPath = tableView.indexPathForSelectedRow {
destinationVC.selectedGoal = goals[indexPath.row]
print(destinationVC.selectedGoal)
}
}
}
此时控制台打印 selectedGoal 的名称、值、添加日期和状态的值,所以我知道它设置正确。
在destinationVC中-
@IBOutlet weak var goalTitleLabel: UILabel!
@IBOutlet weak var goalValueLabel: UILabel!
var selectedGoal: Goal? {
didSet{
if let name = selectedGoal?.name {
goalTitleLabel.text = name
}
}
}
我收到“致命错误,在展开 Optional... 时意外发现 nil”消息。
我证明它已经被设置了,它怎么可能是nil?
提前感谢大家的帮助!
【问题讨论】:
标签: xcode runtime-error