Swift3 使用SideMenu Pod进行导航会在更改屏幕时导致错误

Swift3 使用SideMenu Pod进行导航会在更改屏幕时导致错误,swift3,sidebar,Swift3,Sidebar,我在我的应用程序中使用这个pod:作为我的侧栏。我在故事板中设置了侧栏导航。我的应用程序设计是,我有一个主屏幕和一个带有按钮的侧栏,这些按钮将我带到不同的屏幕。不同的屏幕也有相同的侧栏。我的错误是这样的:我从主屏幕进入侧栏->然后通过侧栏进入屏幕2->我从屏幕2单击侧栏->侧栏从底部出现并占据整个屏幕。 为了修复这个bug,我找到了一个让我不满意的解决方法。我知道我需要关闭侧栏,但是如果我想进入另一个屏幕,我首先看到我来自的屏幕(因为我关闭了),然后它只移动到第二个屏幕。我希望这是有道理的。我想

我在我的应用程序中使用这个pod:作为我的侧栏。我在故事板中设置了侧栏导航。我的应用程序设计是,我有一个主屏幕和一个带有按钮的侧栏,这些按钮将我带到不同的屏幕。不同的屏幕也有相同的侧栏。我的错误是这样的:我从主屏幕进入侧栏->然后通过侧栏进入屏幕2->我从屏幕2单击侧栏->侧栏从底部出现并占据整个屏幕。 为了修复这个bug,我找到了一个让我不满意的解决方法。我知道我需要关闭侧栏,但是如果我想进入另一个屏幕,我首先看到我来自的屏幕(因为我关闭了),然后它只移动到第二个屏幕。我希望这是有道理的。我想在不首先看到主屏幕的情况下切换到第二个屏幕。这是帮助我排除然后更改屏幕的代码:

dismiss(animated: true, completion: {
    goIncident()
})

func goIncident(){
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let window = appDelegate.window
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let rootController = mainStoryboard.instantiateViewController(withIdentifier: "log") as! UINavigationController

     window?.rootViewController = rootController
}

编辑:添加的照片显示了当我只使用函数
goIncident()
而不关闭时的问题。如果我真的错过了,我会看到主屏幕,只有在主屏幕显示后,当它调用新屏幕时才会出现。

所以我使用了一种非常难看的方法来解决这个问题,但我相信这是唯一可能的方法,因为这个Pod不是很灵活,除非我错过了什么。我所做的是:

侧栏视图控制器中

func goLog(){
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeLog"), object: self)
}
override func viewDidLoad(){
    NotificationCenter.default.addObserver(self, selector: #selector(goLog), name: NSNotification.Name(rawValue: "changeLog"), object: nil)
}

func goLog(){
    let logViewController = self.storyboard?.instantiateViewController(withIdentifier: "IncidentLogViewController") as! IncidentLogViewController    
    self.navigationController?.viewControllers = [logViewController]
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dismissSideBar"), object: self)

}
MainViewController
中:

func goLog(){
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeLog"), object: self)
}
override func viewDidLoad(){
    NotificationCenter.default.addObserver(self, selector: #selector(goLog), name: NSNotification.Name(rawValue: "changeLog"), object: nil)
}

func goLog(){
    let logViewController = self.storyboard?.instantiateViewController(withIdentifier: "IncidentLogViewController") as! IncidentLogViewController    
    self.navigationController?.viewControllers = [logViewController]
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dismissSideBar"), object: self)

}

因此,侧栏告诉导航控制器更换其视图控制器,然后在其更换后,导航控制器发回通知以关闭侧栏。非常难看,但实际上工作起来很顺利。

添加屏幕截图也很快,几分钟后