ios - Swift - 摇动手势关闭 subview Controller

标签 ios swift uinavigationcontroller segue uiapplication

我有两个 View Controller ,它们在 Storyboard中定义为,

UIViewController -> (Show Detail Segue) -> UITabBarController

我的问题是;我正在使用一个名为 netfox 的库来调试我的 HTTP 请求。这个图书馆的 UI 是由 Shake Gesture 触发的。但是当我来到模拟器上的 UITabBarController Shake Gesture 时,第一次不起作用。第二次它关闭当前在屏幕上的 ViewController 并且显然是 UITabBarController 的子级并返回到初始的 UIViewController。这就像用 modal segue 连接两个 ViewController 并从 subview 调用 self.dismiss() 一样。

我试图通过以下方式更改 UIApplicationrootViewController

UIApplication.shared.keyWindow.rootViewController = self 

UITabBarControllerviewDidLoad() 方法中,它起作用了。但是,对于此解决方案,作为 UITabBarController 子级的任何 UINavigationControllerUINavigationBar 中的项目(按钮、标题)都丢失了。

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

最佳答案

而不是使用

self.performSegue(withIdentifier:_)

UIViewController 中调用此方法有效:

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

敬此answer .

关于ios - Swift - 摇动手势关闭 subview Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51427470/

相关文章:

iphone - UIView autoResizing 有时会起作用

ios - 搜索数据模型资源时的 nil 路径

ios - XCode 8.1 更新框架不起作用

iphone - iOS - UINavigationController 添加多个正确的项目?

ios - tableView reloadData 在文档目录中删除后不重新加载数据

objective-c - autorelease 在自动引用计数模式下不可用

Swift 属性封装

arrays - 需要帮助在 Swift 2 中的 API 调用中访问第二层数据

iphone - 从 UINavigationControllerDelegate 内部获取当前 View Controller

iPhone Storyboard,以编程方式调用 segues,导航问题