Add selector to UIButton

I have ViewController, and then two different ones ViewControllersthat extend this basic ViewControllerone, one for the iPhone and the other for the iPad.

iPad ViewControllercreates a separate extended one UIViewand sets it as its own look. There are several buttons in this view that I want to add to selector methods as some methods in the main ViewController. How can this be achieved?

So here is a way to visualize this:

Main ViewController
| iPhone ViewController
| iPad ViewController
  | Some UIView Class    --> Button must invoke method in Main View Controller

EDIT: I don't use the interface constructor at all.

+3
source share
2 answers

If I do not understand the question, there is no trick.

(IBAction)buttonPressed:(id)sender , iPad. , self, iPad , .

+2

, , , :

[button addTarget:yourObject action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];

, addTarget MainViewController , MainViewController. Interface Builder, IBAction.

+21

All Articles