How can I make a UIButton perform my class method, +doSomething:(id)sender
, on class MyClass
, after any event like UIControlEventTouchDown
? Can I use -addTarget:action:forControlEvents:
like I do for instance methods?
Thanks in advance.
How can I make a UIButton perform my class method, +doSomething:(id)sender
, on class MyClass
, after any event like UIControlEventTouchDown
? Can I use -addTarget:action:forControlEvents:
like I do for instance methods?
Thanks in advance.
Add an in-between method that will call the Class method.
[button addTarget:self action:@selector(callClassMethod:) forControlEvents: UIControlEventTouchDown];
- (void)callClassMethod:(id)sender {
[MyClass classMethod:sender];
}
Since classes are also ObjC objects, you can use -addTarget:...
as usual:
[button addTarget:[MyClass class]
action:@selector(classMethod:)
forControlEvents:UIControlEventTouchUpInside];