我有我的自定義導航欄中的菜單tableview。如果我點擊一個單元格,它應該帶我到另一個視圖控制器。但是當我點擊它時,我的應用程序崩潰了。storyboard?.instantiateViewController(withIdentifier:「」)as! viewcontroller
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menu_items.count //It has 5 values
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "cell")
cell.textLabel?.text = menu_items[indexPath.row]
cell.textLabel?.textColor = .white
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let item = menu_items[indexPath.row]
if (item == "Patienten") {
tableView.removeFromSuperview()
let vc = self.storyboard?.instantiateViewController(withIdentifier: "patientView") as! patientViewVC //App crashes here
self.present(vc, animated: false, completion: nil)
} else if (item == "Mitarbeiter") {
} else if (item == "Kalender") {
} else if (item == "Tourenplanung") {
tableView.removeFromSuperview()
let vc = storyboard?.instantiateViewController(withIdentifier: "tour") as! tourVC //App crashes here
self.present(vc, animated: false, completion: nil)
}else if (item == "Abmelden") {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "loginvc") as! LoginVC //App crashes here
self.present(vc, animated: false, completion: nil)
}
let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
selectedCell.contentView.backgroundColor = colorLightGreen
}
}
我曾無數次驗證所有標識符名稱和視圖控制器的名字是正確的。
它崩潰?控制檯中的錯誤消息是什麼? 'UIViewController'是否與當前的故事板一樣? – Larme
你確定你有'patientViewVC'在tableview是相同的故事板? –
@Larme我在控制檯中看不到任何錯誤消息,我在該行看到EXC_BAD_INSTRUCTION。 – swiftuser123