How to connect UIButton and method programmatically?

In my UIView displayed.

Inside the same UIView class, I have a method that I would like to execute when a button is clicked.

When everything is done programmatically, without using Interface Builder , how can you link these two together?

+4
source share
2 answers

Use the UIButton addTarget: action: forControlEvents: message to indicate the selector for the UIControlEventTouchUpInside event.

 [myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
+10
source

UIControl addTarget: forControlEvents:

0
source

Source: https://habr.com/ru/post/1382747/


All Articles