【发布时间】:2019-02-03 09:32:36
【问题描述】:
下面代码的第四行出现以下错误...
线程 1:信号 SIGABRT,输出显示 Could not cast value of type 'JobTableViewController' (0x10a20cb80) to 'NSString' (0x10cc5a2a8)。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toDetails" {
let detailController = segue.destination as! JobDetailViewController
detailController.valueToPass = sender as! String
}
}
Job.swift:
class Job {
var text: String = ""
let ref: DatabaseReference!
init(text: String) {
self.text = text
ref = Database.database().reference().child("jobs").childByAutoId()
}
init(snapshot: DataSnapshot)
{
ref = snapshot.ref
if let value = snapshot.value as? [String : Any] {
text = value["text"] as! String
}
}
func save() {
ref.setValue(toDictionary())
}
func toDictionary() -> [String : Any]
{
return [
"text" : text,
]
}
}
【问题讨论】:
-
执行此转场的视图控制器的类是什么?你想传递的价值是什么?
标签: ios swift uitableview nsstring segue