自定义类“无法识别的选择器发送到实例”

时间:2013-03-06 19:18:04

标签: iphone ios objective-c cocoa-touch

背景故事

我目前正在创建一个自定义类来处理/模仿Facebook菜单应用的外观, 我已经在一个单独的项目(工作)中创建了这个功能,并认为使代码可重用是个好主意。

问题

我得到一个“无法识别的选择器发送到实例”错误,而我确实我已经实现了方法“句柄”我无法弄清楚出了什么问题。如果有人愿意帮助我。或者把我推向正确的方向

修改

我的输出窗口生成的完整错误

  

2013-03-06 19:56:39.520 SwipeMenuProject [14347:c07] - [__ NSArrayM句柄:]:无法识别的选择器发送到实例0x7558310

守则

  

UISwipeMenuControl.m

#import "UISwipeMenuControl.h"

@implementation UISwipeMenuControl

@synthesize frontWindow = _frontWindow, backWindow = _backWindow, navController = _navController, btnHandle = _btnHandle;

-(id)init
{
    self.frontWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.backWindow = [[UIWindow alloc] initWithFrame:CGRectMake(-61,0,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height)];

    self.btnHandle = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.btnHandle setFrame:CGRectMake(0, 0, 60, 20)];
    [self.btnHandle setTitle:@"Handle" forState:UIControlStateNormal];

    UIPanGestureRecognizer * dragGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handle:)];
    [self.btnHandle addGestureRecognizer:dragGesture];

    UIViewController * viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    [viewController setTitle:@"Swipe Menu"];
    [viewController.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:self.btnHandle]];

    self.navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [self.frontWindow setRootViewController:self.navController];

    return self;
}

-(UIWindow *)getFrontWindow
{
    return self.frontWindow;
}

-(UIWindow *)getBackWindow
{
    return self.backWindow;
}

-(UINavigationController *)getNavigationController
{
    return self.navController;
}

-(void) setRootViewController:(UIViewController *)viewController
{
    self.navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [viewController.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:self.btnHandle]];
    [self.frontWindow setRootViewController:self.navController];
}
-(void)handle:(id)sender
{
    //unrelated code here
}
  

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UISwipeMenuControl * swipeMenu = [[UISwipeMenuControl alloc] init];

    CustomViewController * cViewController = [[CustomViewController alloc] initWithNibName:nil bundle:nil];
    [swipeMenu setRootViewController:cViewController];

    self.window = [swipeMenu getFrontWindow];
    [self.window setBackgroundColor:[UIColor redColor]];
    [self.window makeKeyAndVisible];

    return YES;
}

1 个答案:

答案 0 :(得分:2)

看起来这是一个所有权/内存问题。当识别器发送其动作时,UISwipeMenuControl似乎被解除分配。

启用僵尸来调查是否存在问题。