2016-02-24 73 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) 
} 

這樣它就知道要遵循哪一個。這也可能取決於你如何繼續觀看視頻。