我需要將touchesBegan的觸摸和事件傳遞給由performSelector調用的我自己的方法。我正在使用NSInvocation來打包參數,但是我遇到了目標問題。如何讓performSelector使用NSInvocation?
我這樣做的原因是我可以處理其他滾動事件。
這裏是我的代碼:
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
UITouch *theTouch = [touches anyObject];
switch ([theTouch tapCount])
{
case 1:
NSInvocation *inv = [NSInvocation invocationWithMethodSignature: [self methodSignatureForSelector:@selector(handleTap: withEvent:)]];
[inv setArgument:&touches atIndex:2];
[inv setArgument:&event atIndex:3];
[inv performSelector:@selector(invokeWithTarget:) withObject:[self target] afterDelay:.5];
break;
}
}
凡handleTap被定義爲:
-(IBAction)handleTap:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}
我的問題是,當我編譯它,我得到一個警告:
'CategoryButton' 很多不響應'目標'
當我運行它時,它崩潰了:
- [CategoryButton目標]:無法識別的選擇發送到實例0x5b39280
我必須承認,我真的不明白什麼目標試圖在這裏做,它是如何設置的。
感謝您的幫助。
感謝您通過NSArray傳遞參數的幫助,這是難題。延遲是爲了管理點擊。如果在此時間內有滾動,則點擊被取消。這種方法似乎工作得很好。 – iphaaw 2011-02-13 23:24:02