0

我有一个错误:

2013-08-01 01:09:18.433 VstupHelper[28332:11303] -[VHMasterViewController popViewController:]: unrecognized selector sent to instance 0x7566410
2013-08-01 01:09:18.434 VstupHelper[28332:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VHMasterViewController popViewController:]:

这是我的代码:

UIButton *bt=[UIButton buttonWithType:UIButtonTypeCustom];
    [bt setFrame:CGRectMake(0, 0, 50, 30)];
    [bt setImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal];
    [bt addTarget:self action:@selector(popViewController:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftButton=[[UIBarButtonItem alloc] initWithCustomView:bt];
    self.navigationItem.leftBarButtonItem=leftButton;

    self.navigationItem.leftBarButtonItem.target = self.revealViewController;
    self.navigationItem.leftBarButtonItem.action = @selector(revealToggle:);

我不擅长英语,所以如果我很难理解,我很抱歉。

4

1 回答 1

2

你有几个问题:

1)当你应该在你popViewController:的.UIViewControllerUINavigationController

2)popViewController:为是否为该过渡设置动画采用 bool 值。使用该操作,默认情况下它会传递给发件人。

UIBarButtonItem3)然后您重新分配按钮的目标和操作(但是当您使用initWithCustomView:初始化程序创建时不会调用这些:请参阅文档)。


如何解决这个问题:

1) 调用您为按钮处理程序创建的方法:

UIButton *bt=[UIButton buttonWithType:UIButtonTypeCustom];
[bt setFrame:CGRectMake(0, 0, 50, 30)];
[bt setImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal];
[bt addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftButton=[[UIBarButtonItem alloc] initWithCustomView:bt];
self.navigationItem.leftBarButtonItem=leftButton;

2)在那个方法中,弹出视图控制器,或者做任何你真正想做的事情:

- (void)buttonTouched:(id)sender 
{
    [self.navigationController popViewController:YES]; 
    //Or what you assigned to the button action:
    [self.revealViewController revealToggle:(not sure what you're supposed to have here)];
}
于 2013-07-31T22:24:21.003 回答