繁体   English   中英

登录后不显示 sideMenu

[英]sideMenu not displayed after login

我已经包括了kukushi侧菜单。 我已经按照文档做了事情。 应用程序委托中代码的屏幕截图如下:

    func setUpHomeVC() {
    var window: UIWindow?

    let storyBoard = UIStoryboard.init(name: "Dashboard", bundle: Bundle.main)
    let contentViewController = storyBoard.instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController
    let menuViewController = storyBoard.instantiateViewController(withIdentifier: "MenuViewCOntroller") as! MenuViewCOntroller
    SideMenuController.preferences.basic.menuWidth = 240
    SideMenuController.preferences.basic.statusBarBehavior = .hideOnMenu
    SideMenuController.preferences.basic.position = .sideBySide
    SideMenuController.preferences.basic.direction = .left
    SideMenuController.preferences.basic.enablePanGesture = true
    SideMenuController.preferences.basic.supportedOrientations = .portrait
    SideMenuController.preferences.basic.shouldRespectLanguageDirection = true
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = SideMenuController(contentViewController: contentViewController,
        menuViewController: menuViewController)
        window?.makeKeyAndVisible()
}

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    setUpHomeVC()
    return true
}

在此处输入图片说明 标识符、类和模块已根据文档添加。 登录后有仪表板,其中包含菜单按钮。 登录时的代码是:

 private func goToDashboard() {
    let dashboard = UIStoryboard(name: "Dashboard", bundle: nil)
    let navView = dashboard.instantiateViewController(identifier: "DashboardViewController") as DashboardViewController
    present(navView,animated: false)

}

在仪表板上有一个具有点击事件的按钮:

  @IBAction func btnMenuClicked(_ sender: Any) {
    print("Menu button has been clicked")
    self.sideMenuController?.revealMenu(animated: true)
}

当我单击该按钮时,会调用打印功能,但未显示菜单。

谁能解释一下。 提前致谢。

你可以像这样设置你的 appDelegate,

  func setUpHomeVC() {
    let storyboard = UIStoryboard(name: "Your Login Storyboard", bundle: nil)
    let initialViewController = storyboard.instantiateViewController(withIdentifier: "LoginVC")
    self.window?.rootViewController = initialViewController
}

   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    setUpHomeVC()
    return true
}

在您的登录事件中:

    private func goToDashboard() {
    self.pushVC()

}

private func pushVC()  {
    let storyBoard = UIStoryboard.init(name: "Dashboard", bundle: Bundle.main)
    let contentViewController = storyBoard.instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController
    let menuViewController = storyBoard.instantiateViewController(withIdentifier: "MenuViewCOntroller") as! MenuViewCOntroller
    SideMenuController.preferences.basic.menuWidth = 240
    SideMenuController.preferences.basic.statusBarBehavior = .hideOnMenu
    SideMenuController.preferences.basic.position = .sideBySide
    SideMenuController.preferences.basic.direction = .left
    SideMenuController.preferences.basic.enablePanGesture = true
    SideMenuController.preferences.basic.supportedOrientations = .portrait
    SideMenuController.preferences.basic.shouldRespectLanguageDirection = true
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.rootViewController = SideMenuController(contentViewController: contentViewController,
                                                    menuViewController: menuViewController)
    window?.makeKeyAndVisible()

}

您的 DashboardVC 应该位于导航控制器中,以便显示侧边菜单。 尝试推动控制器而不是呈现它。如果您在不同的故事板中有控制器,则可以使用此功能:

  func pushVC(storyboardName : String, vcname : String)  {
        let vc = UIStoryboard.init(name: storyboardName, bundle: Bundle.main).instantiateViewController(withIdentifier: vcname)
        self.navigationController?.pushViewController(vc, animated: true)
    }

此外,我建议您了解何时推送、呈现和制作根视图控制器,因为它们都有不同的用途。

我认为您目前的实施是错误的。 问题是我们需要实现和推送视图控制器作为 SideMenuControllers 包,而不是单独的 ViewControlers

如果你想在登录后有侧边菜单,那么首先在你的 didFinishLaunchingWithOptions 中设置你的登录页面。

然后您可以从您的 loginVC 调用 setUpHomeVC。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM