我需要将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