2016-02-24 74 views
0

我试图修复一个编辑segue(在IB中显示),我可以单击工具栏上的“编辑报告详细信息”按钮,它会显示对'配置报告“视图控制器。显示Segue使用错误的presentationViewController,并导致错误的导航

但是,如果我点击取消,它会一直回到我的登录屏幕,因为presentsViewController是一个UINavigationController,即使它不应该。

这是故事板。 http://i.imgur.com/DK4HhpO.png

任何想法?

// 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) 
    } 
} 

回答

0

这是我在我的代码中完成的工作。

@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) 
} 

这样它就知道要遵循哪一个。这也可能取决于你如何继续观看视频。