使用addTarget调用时无法识别的选择器

时间:2013-02-27 09:03:08

标签: iphone xcode ipad uitableview

我在自定义单元格按钮上使用addTarget,如:

[cell.btnGet addTarget:self action:@selector(getLocal:cell:) forControlEvents:UIControlEventTouchUpInside];

应该调用这个方法:

-(void)getLocal:(id)sender withcell:(GroupListCell *)cell
{
    // code for implement
}

但是当我点击按钮时,它会抛出错误:

2013-02-27 14:28:56.533 iOSPlayer[704:11303] -[GroupView getLocal:cell:]: unrecognized selector sent to instance 0x72e1290
2013-02-27 14:28:56.534 iOSPlayer[704:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GroupView getLocal:cell:]: unrecognized selector sent to instance 0x72e1290'

这里有什么问题?

2 个答案:

答案 0 :(得分:1)

试试这个:

[cell.btnGet addTarget:self action:@selector(getLocal:withcell:) forControlEvents:UIControlEventTouchUpInside];

答案 1 :(得分:1)

该行动方法被称为:

getLocal:withcell:

而不是:

getLocal:cell:

它也不匹配任何可接受的操作方法签名,它们是:

- (IBAction)doSomething;
- (IBAction)doSomething:(id)sender;
- (IBAction)action:(id)sender forEvent:(UIEvent *)event;

(见Apple guide