为iOS应用程序实现侧菜单,应用程序在手势上崩溃。

为iOS应用程序实现侧菜单,应用程序在手势上崩溃。,ios,swift,side-menu,Ios,Swift,Side Menu,我正在尝试使用此库为我的iOS应用程序实现侧菜单 通过代码实现,在视图中编写的代码下面没有加载func: let menuRightNavigationController = UISideMenuNavigationController(rootViewController: SideMenuViewController()) SideMenuManager.default.menuRightNavigationController = menuRightNavigation

我正在尝试使用此库为我的iOS应用程序实现侧菜单 通过代码实现,在视图中编写的代码下面没有加载func:

    let menuRightNavigationController = UISideMenuNavigationController(rootViewController: SideMenuViewController())

    SideMenuManager.default.menuRightNavigationController = menuRightNavigationController
    SideMenuManager.default.menuFadeStatusBar = false

    SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
    SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
但应用程序在上面代码的最后两行崩溃,下面的代码是用按钮操作编写的:

    @objc func menuButtonAction(sender: UIButton!) {
    present(SideMenuManager.default.menuRightNavigationController!, animated: true, completion: nil)    
}

伙计们,请帮我处理撞车的事,这样我就可以展示我的配菜了。谢谢

我敢肯定,当您的应用程序在这行中运行到零值时,它会崩溃: SideMenuManager.default.menuAddPanGestureToPresenttoView:self.navigationController!。然而,如果没有崩溃日志,我只能做出一些假设

我假设这里的self指的是UIViewController类。根据navigationController属性,是视图控制器层次结构中作为导航控制器的最近祖先。如果视图控制器未嵌入导航控制器中,则此属性为nil


我建议您确保在强制展开之前启动UINavigationController对象。这里是,这可能有助于您了解导航控制器的概念。

您需要在此基础上更改您的a行代码

SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
对此

SideMenuManager.default.menuAddPanGestureToPresent(toView: self.view)

您可以共享崩溃日志吗?您的应用程序是否嵌入了导航控制器?谢谢,我已将导航控制器嵌入到我的视图控制器中。