Ios Show Segue使用了错误的presentingViewController,并导致错误的导航

Ios Show Segue使用了错误的presentingViewController,并导致错误的导航,ios,swift,Ios,Swift,我正在尝试安装一个编辑序列(在IB中显示),在这里我可以单击工具栏上的“编辑报告详细信息”按钮,它将向“配置报告”视图控制器显示序列 但是,如果我单击“取消”,它会一直返回到我的登录屏幕,因为presentingViewController是UINavigationController,尽管它不应该是 这是故事板 有什么想法吗 // MARK: Navigation @IBAction func cancel(sender: UIBarButtonItem) { // Depending

我正在尝试安装一个编辑序列(在IB中显示),在这里我可以单击工具栏上的“编辑报告详细信息”按钮,它将向“配置报告”视图控制器显示序列

但是,如果我单击“取消”,它会一直返回到我的登录屏幕,因为presentingViewController是UINavigationController,尽管它不应该是

这是故事板

有什么想法吗

// MARK: Navigation
@IBAction func cancel(sender: UIBarButtonItem) {
    // Depending on style of presentation (modal or push presentation), this view controller needs to be dismissed in two different ways.
    let isPresentingInAddItemMode = presentingViewController is UINavigationController

    if isPresentingInAddItemMode {
        dismissViewControllerAnimated(true, completion: nil)
    }
    else {
        // In this mode (push presentation), we need to pop the view controller to get rid of it, rather than dismissing
        navigationController!.popViewControllerAnimated(true)
    }
}

这就是我在代码中所做的一切,它是有效的

@IBAction func cancel(sender: AnyObject) {
    self.navigationController?.popViewControllerAnimated(true)
}
无论何时,您都可能需要检查哪个segue标识符首先发送给您

@IBAction func cancel(sender: AnyObject) {
   if (segue.identifier == "Edit") {
    self.navigationController?.popViewControllerAnimated(true)
   } else if (segue.identifier == "Add") {
    self.navigationController?.popViewControllerAnimated(true)
}
这样它就知道该遵循哪一条。这也可能取决于你是如何从一开始就进入视图的