How can I make UIButton execute my method of class +doSomething:(id)sender in class MyClass after any event, for example UIControlEventTouchDown ? Is it possible to use -addTarget:action:forControlEvents: like I, for example, methods?
+doSomething:(id)sender
MyClass
UIControlEventTouchDown
-addTarget:action:forControlEvents:
Thanks in advance.
Since classes are also ObjC objects, you can use -addTarget:... , as usual:
-addTarget:...
[button addTarget:[MyClass class] action:@selector(classMethod:) forControlEvents:UIControlEventTouchUpInside];
Add an intermediate method that will call the class method.
[button addTarget:self action:@selector(callClassMethod:) forControlEvents: UIControlEventTouchDown]; - (void)callClassMethod:(id)sender { [MyClass classMethod:sender]; }
Source: https://habr.com/ru/post/1300842/More articles:Vectorization for loops in MATLAB - performanceConvert C to PHP? - cAnkhSVN client-side pre-capture capture - code-formattingFire Keydown event in different browsers - firefoxWhy do we put "this" before the parameter? - c #Convert database table structure to XSD - xmlIdentifying an Effective Configuration File - .netselect records that are repeated twice! - sqlRuby / Glibc coredump (double loose or damage) - multithreadingLaTeX \ cite gives [?] - latexAll Articles