我面临一个问题,因为有两种方法我如何显示我的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我的“<返回”消失,只有我添加的按钮 –