我需要将 touchesBegan 中的触摸和事件传递给我自己的由 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' 许多不响应'-target'
当我运行它时,它崩溃了:
-[CategoryButton 目标]:无法识别的选择器发送到实例 0x5b39280
我必须承认我并不真正了解目标在这里试图做什么以及它是如何设置的。
谢谢你的帮助。