Adil Ahamed Adil Ahamed - 6 months ago 101
Swift Question

Navigation bar not showing with MMDrawerController

I am new to swift and iOS development.
In my project i am loading slidein menu with MMDrawerController, it works fine for slide ,but after initializing MMDrawerController in AppDelegate, by top navigation bar [navigation controller] is not getting displayed. commenting MMDrawer initialization shows the navigation bar and click events are firing proper , following is the navigation initialization code ,

func buildNavigationDrawer()
{

// Instantiate Main.storyboard
let mainStoryBoard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)

// Create View Controllers
let mainPage:TabBarViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("TabBarViewController") as! TabBarViewController

let leftSideMenu:LeftSideViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("LeftSideViewController") as! LeftSideViewController

let rightSideMenu:RightSideViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("RightSideViewController") as! RightSideViewController



// Wrap into Navigation controllers
let leftSideMenuNav = UINavigationController(rootViewController:leftSideMenu)
let rightSideMenuNav = UINavigationController(rootViewController:rightSideMenu)

// Cerate MMDrawerController
drawerContainer = MMDrawerController(centerViewController: mainPage, leftDrawerViewController: leftSideMenuNav, rightDrawerViewController: rightSideMenuNav)

drawerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView
drawerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView

// Assign MMDrawerController to our window's root ViewController
window?.rootViewController = drawerContainer

}

Answer

In one of the examples about the MMDrawerController there is this code:

 self.drawerController = [[MMDrawerController alloc]
                     initWithCenterViewController:navigationController....

Try to change your mainPage with a UINavigationController with the rootViewController linked to the TabBarViewController and you should be solve the issue.

DETAIL:

// Wrap into Navigation controllers
            let leftSideMenuNav = UINavigationController(rootViewController:leftSideMenu)
            let rightSideMenuNav = UINavigationController(rootViewController:rightSideMenu)
            let centerMenuNav = UINavigationController(rootViewController: mainPage)

            // Cerate MMDrawerController
            drawerContainer = MMDrawerController(centerViewController: centerMenuNav, leftDrawerViewController: leftSideMenuNav, rightDrawerViewController: rightSideMenuNav)
Comments