我搜索了很多,但无法找到解决我的问题的方法。我有一个函数,我想在调用UIBarButtonItem的时候调用它作为选择器。我的UIViewController嵌入在导航控制器中。UIBarButtonItem操作失败,无法识别选择器
在.h文件中
- (IBAction)EventsAction:(UIBarButtonItem *)sender;
在我的.m文件我在viewDidLoad方法
UIBarButtonItem *composer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(EventActions:)];
composer.tag = 0;
UIBarButtonItem *notifList = [[UIBarButtonItem alloc] initWithTitle:@"!N!" style:UIBarButtonItemStyleBordered target:self action:@selector(EventActions:)];
notifList.tag = 1;
NSArray *buttonArr = [[NSArray alloc] initWithObjects:composer, notifList, nil];
self.navigationItem.rightBarButtonItems = buttonArr;
创建我UIBarButtonItems和函数的定义为:
- (IBAction)EventsAction:(UIBarButtonItem *)sender {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"connection"]) {
if (sender.tag == 0) {
[self performSegueWithIdentifier:@"newEvent" sender:self];
}
if (sender.tag == 1) {
[self performSegueWithIdentifier:@"notificationView" sender:self];
}
}
else {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"NoConnectionTitle", nil) message:NSLocalizedString(@"NoConnection", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Tamam", nil) otherButtonTitles:nil];
[myAlert show];
}
}
然而,当我运行此代码,点击按钮,我得到了无法识别的选择错误
终止应用程序由于未捕获的异常“NSInvalidArgumentException”,理由之一:“ - [BIAllEventsController EventActions:] :无法识别的选择器发送到实例0x1ddc1400'
我也尝试将IBAction更改为void,但并未解决我的问题。
编辑
谢谢大家在百忙之中的愚蠢的错误。虽然它教导非常重要的经验教训,例如:
- 从不信任自动完成
- 一个良好的睡眠不会解决所有的问题
这是因为无法识别选择器'EventActions:'。仔细看看它的名字。 – 2013-05-07 09:22:57