我有兩個不同的ViewControllers,細節&搜索。去細節的賽段工作正常,但去搜索一直不斷崩潰的應用程序。我已經花了兩個小時閱讀類似的問題,但沒有人似乎有同樣的問題:Xcode Segue「無法投射類型的值」
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let detailVC = segue.destination as! DetailViewController
if segue.identifier == "newDocSegue" {
// Create a new document and pass it to the detail view.
detailVC.doc = Document()
detailVC.isAddAction = true
}
if segue.identifier == "editDocSegue" {
// Load the existing document into the detail view, for editing.
let indexPath = tableView.indexPath(for: sender as! UITableViewCell)!
detailVC.doc = Document[indexPath.row]
detailVC.isAddAction = false
}
else if segue.identifier == "searchSegue" {
shouldPerformSegue(withIdentifier: "searchSegue", sender: Any?.self)
}
}
segues從TableViewController到ViewControllers –
shouldPerformSegue(withIdentifier:「searchSegue」,sender:Any?.self),爲什麼這行代碼在那裏? – raki
您在第二個if語句中缺少'else' – Fonix