MMDrawerController无法识别的选择器 [英] MMDrawerController unrecognized selector

查看:124
本文介绍了MMDrawerController无法识别的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程式设定siderbar导览选单。我使用MMDrawerController lib,但我遇到了一个问题。我添加了一个按钮,并使用这些方法来调用侧边栏:

   - (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];
}

我使用一个带有View控制器的导航控制器, m调用这个方法。这个viewcontroller被称为ViewController2。



每当我按下按钮拉出sidemenu,它崩溃,并返回这个错误:



* 由于未捕获的异常NSInvalidArgumentException终止应用程序,原因:' - [ViewController2 mm_drawerController]:无法识别的选择器发送到实例0x835b440'



我做错了什么?



编辑:



AppDelegate.h

  #importAppDelegate.h
#importMMDrawerController.h
#importViewController2.h
#importMMLeftSideDrawerViewController.h
#importMMRightSideDrawerViewController.h
#importMMDrawerVisualState.h
#importMMDrawerVisualStateManager.h

#导入< 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
{
//当应用程序将从活动状态转换为非活动状态时发送。这可能发生在某些类型的临时中断(例如来电或SMS消息)或用户退出应用程序时,并且开始转换到后台状态。
//使用此方法暂停正在进行的任务,禁用计时器,并降低OpenGL ES帧速率。游戏应该使用这种方法暂停游戏。
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
//使用此方法释放共享资源,保存用户数据,并存储足够的应用程序状态信息以将应用程序恢复到其当前状态,以防日后终止。
//如果您的应用程序支持后台执行,则调用此方法,而不是applicationWillTerminate:当用户退出时。
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
//调用作为从后台到非活动状态的转换的一部分;在这里你可以撤消许多在输入背景所做的更改。
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
//在应用程序重新启动已暂停(或尚未启动)是无效的。如果应用程序先前在后台,则可选择刷新用户界面。
}

- (void)applicationWillTerminate:(UIApplication *)application
{
//当应用程序即将终止时调用。如果适当,保存数据。另请参见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


解决方案>

查看示例,如果您使用的是导航,请尝试使用



(或者如果不是则交换视图)



[(UINavigationController *)self.mm_drawerController.centerViewController pushViewController:animated:YES];


I'm trying to setup a siderbar navigation menu for my app. I'm using the MMDrawerController lib, but I'm running into an issue. I've added a button and use these methods to call the sidebar:

-(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];
}

I'm using a Navigation Controller with a View Controller attached in which I'm calling this method. This viewcontroller is called ViewController2.

Whenever I press the button to pull out the sidemenu, it crashes and returns this error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController2 mm_drawerController]: unrecognized selector sent to instance 0x835b440'

What am I doing wrong?

edit:

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

解决方案

Take a look at the example have you tried something like in case you are using navigation

(or swapping view in case you are not)

[(UINavigationController*)self.mm_drawerController.centerViewController pushViewController: animated:YES];

这篇关于MMDrawerController无法识别的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆