James Leonard
James Leonard

Reputation: 3763

How to connect UIButton and a method programmatically?

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?

Upvotes: 4

Views: 1799

Answers (2)

Hot Licks
Hot Licks

Reputation: 47759

UIControl addTarget: forControlEvents:

Upvotes: 0

Dan
Dan

Reputation: 17445

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

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

Upvotes: 10

Related Questions