how to programmatically fake a touch event to a UIButton? how to programmatically fake a touch event to a UIButton? ios ios

how to programmatically fake a touch event to a UIButton?


It turns out that

[buttonObj sendActionsForControlEvents:UIControlEventTouchUpInside];

got me exactly what I needed, in this case.

EDIT: Don't forget to do this in the main thread, to get results similar to a user-press.


For Swift 3:

buttonObj.sendActions(for: .touchUpInside)


An update to this answer for Swift

buttonObj.sendActionsForControlEvents(.TouchUpInside)

EDIT: Updated for Swift 3

buttonObj.sendActions(for: .touchUpInside)


Swift 3:

self.btn.sendActions(for: .touchUpInside)