【问题标题】:Swift - Shake gesture dismisses the child view controllerSwift - 摇动手势会关闭子视图控制器
【发布时间】:2018-12-27 21:01:45
【问题描述】:

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

UIViewController -> (Show Detail Segue) -> UITabBarController

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

我试图将UIApplicationrootViewController 更改为,

UIApplication.shared.keyWindow.rootViewController = self 

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

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

【问题讨论】:

    标签: ios swift uinavigationcontroller segue uiapplication


    【解决方案1】:

    而不是使用

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      相关资源
      最近更新 更多