Clifton Labrum
Clifton Labrum

Reputation: 14068

Getting Started with MMDrawerController

I'm trying to get MMDrawerController to work, and I'm having trouble.

Here's is how much app is structured in my storyboard:

enter image description here

Here's how I'm attempting to initialize it from within my root view controller:

//LCViewController.m

#import "LCViewController.h"
#import "MMDrawerController.h"

@interface LCViewController ()
  @property (nonatomic,strong) MMDrawerController * drawerController;
@end

@implementation LCViewController

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.drawerController = [[MMDrawerController alloc]
                           initWithCenterViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"centerNav"]
                           leftDrawerViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"menu"]
                           rightDrawerViewController:nil];
}

...

@end

When I build my app, all I see is my root view controller. Is there something else I'm supposed to do to implement the drawer functionality?

I created a demo project to show how I'm trying to set up my app. You can download the Xcode workspace here. Thanks in advance for your help!

I'm using Xcode 5 and iOS 7

Upvotes: 3

Views: 8182

Answers (1)

Patrick Goley
Patrick Goley

Reputation: 5417

EDIT: Sorry I initially misunderstood your app structure. The MMDrawerController should be the root view controller of your application. You should move this code from viewDidLoad to application:didFinishLaunchingWithOptions:. Add an MMDrawerController property to your app delegate, init the drawer controller with your appropriate views, and set the drawer controller to the rootViewController on your UIWindow. Do this along with setting the gesture modes as I described below and the drawer should work.

To get the basic open/closing gestures, set this properties on your drawer controller:

self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
self.drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;

These properties default to MMOpenDrawerGestureModeNone which is why you couldn't make anything slide. You can have a look at the MMOpenDrawerGestureMode and MMCloseDrawerGestureMode bitmasks to get finer grained settings if you desire.

You can also create UI controls that toggle the drawer by calling toggleDrawerSide: animated: completion:.

Upvotes: 8

Related Questions