2013-09-03 3 views
0

J'essaie de configurer un menu de navigation siderbar pour mon application. J'utilise la bibliothèque MMDrawerController, mais je rencontre un problème. J'ai ajouté un bouton et utiliser ces méthodes pour appeler la barre latérale:MMDrawerController sélecteur non reconnu

-(void)setupLeftMenuButton{ 
    MMDrawerBarButtonItem * leftDrawerButton = [[MMDrawerBarButtonItem alloc] initWithTarget:self action:@selector(leftDrawerButtonPress:)]; 
    [self.navigationItem setLeftBarButtonItem:leftDrawerButton animated:YES]; 
} 

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

J'utilise un contrôleur de navigation avec un View Controller attaché dans lequel j'appelle cette méthode. Ce viewcontroller s'appelle ViewController2.

Chaque fois que j'appuie sur le bouton pour tirer le sidemenu, il se bloque et renvoie cette erreur:

* Mettre fin application en raison d'une exception non interceptée 'NSInvalidArgumentException', raison: « - [ViewController2 mm_drawerController]: sélecteur non reconnu envoyé à l'instance 0x835b440 '

Qu'est-ce que je fais mal?

modifier:

AppDelegate.h

#import "AppDelegate.h" 
#import "MMDrawerController.h" 
#import "ViewController2.h" 
#import "MMLeftSideDrawerViewController.h" 
#import "MMRightSideDrawerViewController.h" 
#import "MMDrawerVisualState.h" 
#import "MMDrawerVisualStateManager.h" 

#import <QuartzCore/QuartzCore.h> 

@interface AppDelegate() 

@property (nonatomic,strong) MMDrawerController * drawerController; 

@end 

@implementation AppDelegate 
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
    UIViewController * leftSideDrawerViewController = [[MMLeftSideDrawerViewController alloc] init]; 

    UIViewController * centerViewController = [[ViewController2 alloc] init]; // MAYBE SOMETHING WRONG HERE? 

    UIViewController * rightSideDrawerViewController = [[MMRightSideDrawerViewController alloc] init]; 

    UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController]; 
    [navigationController setRestorationIdentifier:@"MMCenterNavigationControllerRestorationKey"]; 

    self.drawerController = [[MMDrawerController alloc] 
          initWithCenterViewController:navigationController 
          leftDrawerViewController:leftSideDrawerViewController 
          rightDrawerViewController:rightSideDrawerViewController]; 
    [self.drawerController setRestorationIdentifier:@"MMDrawer"]; 
    [self.drawerController setMaximumRightDrawerWidth:200.0]; 
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll]; 
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll]; 

    [self.drawerController 
    setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) { 
     MMDrawerControllerDrawerVisualStateBlock block; 
     block = [[MMDrawerVisualStateManager sharedManager] 
        drawerVisualStateBlockForDrawerSide:drawerSide]; 
     if(block){ 
      block(drawerController, drawerSide, percentVisible); 
     } 
    }]; 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self.window setRootViewController:self.drawerController]; 

    return YES; 
} 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 

- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder{ 
    return YES; 
} 

- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder{ 
    return YES; 
} 


- (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder 
{ 
    NSString * key = [identifierComponents lastObject]; 
    if([key isEqualToString:@"MMDrawer"]){ 
     return self.window.rootViewController; 
    } 
    else if ([key isEqualToString:@"MMCenterNavigationControllerRestorationKey"]) { 
     return ((MMDrawerController *)self.window.rootViewController).centerViewController; 
    } 
    else if ([key isEqualToString:@"MMLeftSideDrawerController"]){ 
     return ((MMDrawerController *)self.window.rootViewController).leftDrawerViewController; 
    } 
    else if ([key isEqualToString:@"MMRightSideDrawerController"]){ 
     return ((MMDrawerController *)self.window.rootViewController).rightDrawerViewController; 
    } 
    return nil; 
} 

@end 
+0

Comment configurer root MMDrawer VC? –

+0

Il est expliqué ici: https://github.com/mutualmobile/MMDrawerController Mais je ne l'ai pas encore fait .. – Cake

+0

Enquêter AppDelegate.m dans l'exemple de code et la racine d'installation MMDrawer pour votre VC –

Répondre

0

Jetez un oeil à l'exemple avez-vous essayé quelque chose comme dans le cas où vous utilisez la navigation

(ou vue au cas où vous permutant n'êtes pas

[(UINavigationController *) self.mm_drawerController.centerViewController pushViewController: animé: OUI];

Questions connexes