我面臨一個問題,因爲有兩種方法我如何顯示我的ViewController
。UIBarButtonItem取決於演示文稿。 Swift3
- 第一種方式是
performSegue(withIdentifier: "segue", sender: self)
它正常工作,因爲那時我在navigationItem
有這樣的後退按鈕:
然後我使用此代碼來呈現與第一種情況相同的
ViewController
(來自另一個viewController
):let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let navVC = storyboard.instantiateViewController(withIdentifier: "navViewController") as! UINavigationController let vc = navVC.topViewController as! ViewController self.present(navVC, animated: true, completion: nil)
但當時我沒有在我的ViewController
任何後退按鈕。
我的問題是:我怎樣才能讓我的backButton (exactly how it is)
當我使用這個功能:performSegue(withIdentifier: "segue", sender: self)
,但添加按鈕(可以看看不同),當我使用此功能:self.present(navVC, animated: true, completion: nil)
注:在我的情況1我的segue直接連接到ViewController
,但在情況2中,我在此UINavigationController
中出現UINavigationController
和ViewController
是embed in
。
編輯:我試過這個代碼,但它始終打印:"1........."
:
if self.presentingViewController != nil {
print("1..........")
} else if self.navigationController?.presentingViewController?.presentedViewController == self.navigationController {
return print("2.........")
} else if self.tabBarController?.presentingViewController is UITabBarController {
return print("3........")
}
而且也是這個代碼打印:"Else.............."
:
let isPresentingInAddMealMode = presentedViewController is UINavigationController
if isPresentingInAddMealMode {
print("FirstOption......................")
} else {
print("Else......................")
}
如果您需要更多的信息只是讓我知道。 非常感謝。
當你提出一個視圖控制器作爲一個模式,你需要自己添加的按鈕navigationItem。 – Sealos
我知道,但是當我添加一個按鈕navigationItem我的「<返回」消失,只有我添加的按鈕 –