Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger UIButton action programmatically

I have several buttons in one class and their actions are separate. I created the instance of that class in another class, and I have the UIButton array in the 2nd class. I want to call each button's action programmatically. Is there any way to do this in iOS?

like image 299
Neenu Avatar asked Nov 12 '14 11:11

Neenu


2 Answers

Swift 3.0/4.0/5.0

button.sendActions(for: .touchUpInside)
like image 45
Tal Zion Avatar answered Sep 28 '22 06:09

Tal Zion


UIButton has a method to invoke the targets/selectors that are linked to a certain control event:

[button sendActionsForControlEvents:UIControlEventTouchUpInside];

like image 169
Thomas Keuleers Avatar answered Sep 28 '22 06:09

Thomas Keuleers