假设我要创建以下手势识别器
UITapGestureRecognizer * c1 = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector([[MyGestureRecognizer ViewWasClicked1:]]; // error
[c1 setNumberOfTapsRequired:1];
[c1 setNumberOfTouchesRequired:1];
[[self view] addGestureRecognizer:c1];
但我想在一个单独的类上调用选择器。我有方法:
+ (void)ViewWasClicked1:(UITapGestureRecognizer *)sender {
NSLog(@"click1 mouse down");
}
MyGestureRecognizer类中的。我可以找到什么?
答案 0 :(得分:13)
语法为:
UITapGestureRecognizer * c1 = [[UITapGestureRecognizer alloc]
initWithTarget:[MyGestureRecognizer class]
action:@selector(ViewWasClicked1:)]; // error
答案 1 :(得分:0)
要检查并调用静态方法,您可以执行以下操作:
SEL staticMethodSelector = @selector(methodName);
if ([[ClassName class] respondsToSelector:staticMethodSelector]) {
[[ClassName class] performSelector:staticMethodSelector];
}