1

I'm using MMDrawerController in my project and I don't want it to be the rootViewController. Also I'm using storyboard to set the UI. Most sample code doesn't present like this. So I'm a little confuse how to do it.

I've set a FirstViewController embed with navigationController and there is a Button on it. ButtonClick push the controller to CenterViewController.

Here is my code...

FirstViewController.m

UIViewController * centerViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
UIViewController * rightSideDrawerViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];

self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerViewController rightDrawerViewController:rightSideDrawerViewController];

[self.drawerController setShowsShadow:NO];
[self.drawerController setMaximumRightDrawerWidth:150.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

CenterViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
MMDrawerBarButtonItem * rightDrawerButton = [[MMDrawerBarButtonItem alloc] initWithTarget:self action:@selector(rightDrawerButtonPress:)];
[self.navigationItem setRightBarButtonItem:rightDrawerButton animated:YES];
}

-(void)rightDrawerButtonPress:(id)sender{
[self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
}

RightViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor]; 
}

It can't work. I'm confuse whether should I put a MMDrawerController in storyboard?

Jenny
  • 351
  • 3
  • 19
  • Don't put it in storyboard. I faced difficulties when trying to use with storyboard. So in last, I switched to nib approach. – NightFury Dec 30 '14 at 07:31

1 Answers1

0

you can use following code in application:didFinishLaunchingWithOptions:

application:didFinishLaunchingWithOptions but still MMDrawerController will be your root.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];

UIViewController * leftSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
 @"LeftMenu"];

UIViewController * centerSideNavController = [storyboard instantiateViewControllerWithIdentifier : @"Home"];

UIViewController * rightSideNavController = [storyboard instantiateViewControllerWithIdentifier :
 @"RightMenu"];


UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerSideNavController];
self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:navigationController leftDrawerViewController:leftSideNavController rightDrawerViewController:rightSideNavController];



[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];


[self.window setRootViewController:self.drawerController];
/* Optional - To define Drawer width */
[self.drawerController setMaximumRightDrawerWidth:280.0];

[self.drawerController setMaximumLeftDrawerWidth:280.0];

[self.window makeKeyAndVisible];

Hope this helps.

Mojo Jojo
  • 188
  • 4
  • 16