Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a UIButton perform my class method when tapped?

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.

like image 580
cduck Avatar asked Dec 17 '22 03:12

cduck


1 Answers

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

[button addTarget:[MyClass class]
           action:@selector(classMethod:)
 forControlEvents:UIControlEventTouchUpInside];
like image 143
kennytm Avatar answered Feb 05 '23 17:02

kennytm