首页 > 解决方案 > Swift - 摇动手势会关闭子视图控制器

问题描述

我有两个视图控制器,它们在情节提要中定义为,

UIViewController -> (Show Detail Segue) -> UITabBarController

我的问题是;我正在使用一个调用netfox来调试我的HTTP请求的库。这个图书馆UI是由 触发的Shake Gesture。但是当我第一次来到UITabBarController Shake Gesture模拟器时不起作用。在第二次,它 消除了ViewController当前在屏幕上的,显然是一个孩子,UITabBarController并回到最初的UIViewController. 这就像用segue连接两个ViewControllers并从孩子那里调用一个。modalself.dismiss()

我试图改变rootViewControllerUIApplication

UIApplication.shared.keyWindow.rootViewController = self 

viewDidLoad()方法中UITabBarController,它奏效了。但是,对于此解决方案,缺少UINavigationBar任何子项UINavigationController中的项目(按钮、标题)。UITabBarController

我不知道为什么会这样。如果在我解决这个问题时有人帮助我,我将不胜感激。

标签: iosswiftuinavigationcontrollersegueuiapplication

解决方案


而不是使用

self.performSegue(withIdentifier:_)

调用这个UIViewController已经奏效了:

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewControllerWithIdentifier("tabBarcontroller") as UITabBarController  
UIApplication.sharedApplication().keyWindow?.rootViewController = viewController;

尊重这个答案


推荐阅读