views:

202

answers:

2

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.

A: 

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];
}
coneybeare
This would work but I want to avoid the inter-dependencies between classes this approach creates. Any other ideas?
cduck
+3  A: 

Since classes are also ObjC objects, you can use -addTarget:... as usual:

[button addTarget:[MyClass class]
           action:@selector(classMethod:)
 forControlEvents:UIControlEventTouchUpInside];
KennyTM