我有一个splitView。左侧(MasterViewController)是一张桌子,上面装有对象,用A,B,C,D表示,每个对象位于其自己的单元格中。因此,当选择A或B时,我希望splitview的右侧调出DetailViewController。但是C和D我希望右侧显示出自己的单独的View Controller来代替DetailViewController。这是我遇到的问题。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let object = dailyAgenda[indexPath.row]
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
if object == "A" {
controller.textDescription = "This is A"
}
else {
controller.textDescription = indepthDescript[indexPath.row]
}
}}
if segue.identifier == "CSegue" {
let controller = (segue.destination as! UINavigationController).topViewController as! CViewController
}
if segue.identifier == "DSegue" {
let controller = (segue.destination as! UINavigationController).topViewController as! DViewController
}}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let indexPath = tableView.indexPathForSelectedRow {
let object = dailyAgenda[indexPath.row]
if object == "C" {
self.performSegue(withIdentifier: "CSegue", sender: self)
}
if object == "D" {
self.performSegue(withIdentifier: "DSegue", sender: self)
}
else {
self.performSegue(withIdentifier: "showDetail", sender: self)
}}}
每次我运行它时,A和B都起作用,但是当我尝试C或D时,我在这里遇到错误
在segue.identifier ==“ showDetail”下。我不知道为什么C和D调用showDetail标识符。任何帮助或解释将不胜感激。这是情节提要。