Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect UIButton and a method programmatically?

Tags:

objective-c

In my UIView, i have a UIButton displayed.

Inside same UIView class i have a method i'd like to be executed when button is pressed.

When everything is done programmatically, without the use of Interface Builder, how can one link the two together?

like image 266
James Leonard Avatar asked Dec 27 '22 10:12

James Leonard


1 Answers

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

[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
like image 181
Dan Avatar answered Feb 03 '23 12:02

Dan