【发布时间】:2016-05-30 21:50:23
【问题描述】:
在我的代码中,我需要遍历导航层次结构,这就是为什么我在 UINavigationController 中有一个 UIViewController。
如果用户在一个单元格上按标签并且有下一个级别,我会再次创建相同的UIViewController 并将其推送到UINavigationController。这很好用。
但是当我到达层次结构的末尾并尝试performSegueWithIdentifier,去另一个控制器查看详细信息时,应用程序崩溃并说
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<myproject.MenuController: 0x7fb2e0ea9ef0>)
has no segue with identifier 'showDetail''
但是我检查了 InterfaceBuilder,一切都很好。 有趣的是,如果我不推动下一级导航并直接执行对新控制器的 segue,一切正常。
我还尝试推送新的控制器,就像我正在使用导航一样,但随后它尝试访问奇怪的是 nil 的新控制器委托并崩溃。
有人知道怎么做吗?
完整代码(在 MenuContoller 内)
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
//self.performSegueWithIdentifier("showDetail", sender: self)
let clickedCell = self.tableViewItems[indexPath.row]
print("Selected \(clickedCell.itemID)")
// Check if subview has children, then we push a deeper level on the navigation controller
if (menuItems.filter{$0.parentID == clickedCell.itemID}.count > 0) {
let subNavigationController = MenuController()
// Set the currentNavigationItemID for the new view controller
subNavigationController.currentNavigationItemID = clickedCell.itemID
subNavigationController.title = clickedCell.itemDisplayName
self.navigationController?.pushViewController(subNavigationController, animated: true)
} else {
// Load new Controller to show details
self.performSegueWithIdentifier("showDetail", sender: self)
// let subNavigationController = ProductListViewController()
// subNavigationController.currentCategoryID = clickedCell.itemID
// self.navigationController?.pushViewController(subNavigationController, animated: true)
}
【问题讨论】:
标签: ios swift uiviewcontroller segue