how to programmatically fake a touch event to a UIButton?

后端 未结 8 1846
余生分开走
余生分开走 2020-11-29 15:48

I\'m writing some unit tests and, because of the nature of this particular app, it\'s important that I get as high up the UI chain as possible. So, what I\'d l

8条回答
  •  -上瘾入骨i
    2020-11-29 16:13

    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)

提交回复
热议问题