多个条形按钮上的未声明选择器

时间:2014-02-20 05:52:38

标签: iphone ios7 navigation uinavigationbar

我在以下数据上收到“未声明的选择器deleteHorse”的警告。该警告也会失败。

ViewController.h文件包含以下内容:

- (IBAction)deleteHorse:(id)sender;
- (IBAction)editHorse:(id)sender;

ViewController.m文件包含以下内容:

- (void)deleteHorse:(id)sender
{
if(self.uniqueId > 0)
{
    self.eqDatabase = [[EQDatabase alloc] init];
    [eqDatabase initDatabase];

    EQHorseDetailsInfo *horsedetails = [[EQHorseDetailsInfo alloc] init];
    horsedetails.uniqueId = self.uniqueId;
    [eqDatabase deleteHorseData:horsedetails];

    [self.navigationController popViewControllerAnimated:YES];

}
}

-(void)editHorse:(id)sender
{
NSLog(@"EditingHorse");
}


-(void)viewDidLoad
{
[super viewDidLoad];

UIBarButtonItem *deleteItem= [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
    target:self
    action:@selector(deleteHorse)];   ERROR IS HERE @selector
UIBarButtonItem *editItem = [[UIBarButtonItem alloc]   
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self 
action:@selector(editHorse)];  AND -(void)viewDidLoad
{
[super viewDidLoad];

UIBarButtonItem *deleteItem= [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
    target:self
    action:@selector(deleteHorse)];
UIBarButtonItem *editItem = [[UIBarButtonItem alloc]  
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self  
action:@selector(editHorse)];

NSArray *actionButtonItems = [[NSArray alloc] initWithObjects:deleteItem, editItem,
nil];
self.navigationItem.rightBarButtonItems = actionButtonItems;
}


NSArray *actionButtonItems = [[NSArray alloc] initWithObjects:deleteItem, editItem,
nil];
self.navigationItem.rightBarButtonItems = actionButtonItems;
}

我已经对此进行了搜索。

1 个答案:

答案 0 :(得分:1)

您需要为选择器添加:,因为deleteHorse有参数:

UIBarButtonItem *deleteItem= [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
    target:self
    action:@selector(deleteHorse:)];