我试图以编程方式添加一个按钮,在按下它时,某个对象正在被传递。我不断收到“发送无法识别的选择器”异常。你能建议代码有什么问题吗:
// allocate the details button's action
SEL selector = @selector(showPropertyDetails:forProperty:);
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
//The invocation object must retain its arguments
[property retain];
//Set the arguments
[invocation setTarget:self];
[invocation setArgument:&property atIndex:3];
[(UIButton*)[myView viewWithTag:15] addTarget:self action:@selector(selector) forControlEvents:UIControlEventTouchDown];
再往下看,同一类中的方法如下所示:
-(void) showPropertyDetails:(id)something forProperty:(Property *)property {
int i=0;
}