Call the static method selector from a separate class

let's say I want to create the next gesture recognizer

UITapGestureRecognizer * c1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector([[MyGestureRecognizer ViewWasClicked1:]]; // error [c1 setNumberOfTapsRequired:1]; [c1 setNumberOfTouchesRequired:1]; [[self view] addGestureRecognizer:c1]; 

but I want to call the selector in a separate class. I have a method:

 + (void)ViewWasClicked1:(UITapGestureRecognizer *)sender { NSLog(@"click1 mouse down"); } 

in the class MyGestureRecognizer. Is it possible that I'm looking for?

+6
source share
2 answers

Syntax:

 UITapGestureRecognizer * c1 = [[UITapGestureRecognizer alloc] initWithTarget:[MyGestureRecognizer class] action:@selector(ViewWasClicked1:)]; // error 
+13
source

To test and call static methods, you can do this:

 SEL staticMethodSelector = @selector(methodName); if ([[ClassName class] respondsToSelector:staticMethodSelector]) { [[ClassName class] performSelector:staticMethodSelector]; } 
0
source

Source: https://habr.com/ru/post/914943/


All Articles