我想以一種按下它的方式編程添加一個按鈕,某個對象正在傳遞。我一直在收到「無法識別的選擇器發送」異常。你可以建議什麼是錯的代碼:UIButton與NSInvocation
// 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;
}
所以你的意思是在點擊一個按鈕是發送多個參數的唯一途徑使用集合對象(字典,數組等),因爲他們將始終只有一個參數? – Amarsh 2010-09-13 11:02:18
@Amarsh:我的意思是你不能在這裏使用incovations等,而是必須將信息和關係存儲在其他地方的按鈕。 – 2010-09-13 11:38:50
@George:是的,謝謝。您的評論確實幫助我解決了我的問題。 Thans爲此。 – Amarsh 2010-09-13 23:14:57