我有以下代码,它设置并显示了要嵌入到UINavigationController中的UIViewController:
private func transitionToMainVC() {
let vc = UINavigationController(rootViewController: SpacesVC())
DispatchQueue.main.async {
self.show(vc, sender: self)
}
}现在,在SpacesVC中,我想要show()另一个UIViewController,但是在“父”UINavigationController之外。
当我在SpacesVC中使用以下代码时
// Called by a button touch up inside
@objc private func transitionToMainVC() {
let vc = NextVC()
self.show(vc, sender: self)
}它会转换到NextVC,但会在屏幕顶部显示导航栏;也就是说,新的视图控制器仍然嵌入在第一个代码片段中定义的UINavigationController下。
我知道在NextVC中隐藏导航栏的可能性如下:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navController.isNavigationBarHidden = true
}但是我想在不嵌入导航控制器的情况下对NextVC进行show(),因为我不再需要它了。我该怎么做呢?
发布于 2019-03-02 00:05:01
使用this method而不是show。
func present(_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil)https://stackoverflow.com/questions/54948029
复制相似问题