1

我正在使用 CosmicMaterial ( http://www.cosmicmind.io/material ) 来实现 Sidemenu 或抽屉菜单。我已经阅读了文档以及如何运行这个酷库的示例项目。我能够看到 CosmicMaterial 的 Sidemenu 演示。

一个问题是我很难弄清楚如何在 Sidemenu 中嵌入导航控制器。

我在 Appdelegate 中的代码 didFinishLaunchingWithOptions

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        // Get view controllers from storyboard
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let homeTableViewController = storyboard.instantiateViewControllerWithIdentifier("HomeTableViewController") as! HomeTableViewController
        let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideTableViewController") as! SideTableViewController

//        var navigationController = storyboard.instantiateViewControllerWithIdentifier("RootNavigationController") as! NavigationController
//        
//        var sideNavigationController = storyboard.instantiateViewControllerWithIdentifier("SideNavigationController") as! NavigationController
//        
//        navigationController = NavigationController(rootViewController: homeTableViewController)
//        sideNavigationController = NavigationController(rootViewController: sideViewController)
//        
//        
        // Configure the window with the SideNavigationController as the root view controller
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.rootViewController = SideNavigationController(rootViewController: homeTableViewController, leftViewController: sideViewController)
        window?.makeKeyAndVisible()

        return true
    }

这是我在故事板中的布局。每个 xib 的所有 id 都已设置。

在此处输入图像描述

4

1 回答 1

1

我以前也有同样的问题。我刚刚发现我分配的 navigonController 不正确。请参阅以下代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Get view controllers from storyboard
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let rootViewController = storyboard.instantiateViewControllerWithIdentifier("RootViewController") as! RootViewController
    let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideViewController") as! SideViewController

    let navCon2 = NavigationController(rootViewController: sideViewController)
    let navCon = NavigationController(rootViewController: rootViewController)

    let sideNavigationController = SideNavigationController(rootViewController: navCon, leftViewController: navCon2)
    sideNavigationController.enabledLeftTapGesture = true
    sideNavigationController.enabledLeftPanGesture = true
    sideNavigationController.enableHideStatusbar = false

    // Configure the window with the SideNavigationController as the root view controller
    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    window?.rootViewController = sideNavigationController
    window?.makeKeyAndVisible()
    return true
}

请注意,您必须正确设置 SideNavigationController 的属性。并取消隐藏状态栏,否则在显示侧边菜单时会遇到烦人的错误。

干杯!

于 2016-05-28T05:36:52.813 回答