how to programmatically fake a touch event to a UIButton?

后端 未结 8 1855
余生分开走
余生分开走 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条回答
  •  清酒与你
    2020-11-29 16:18

    In this case, UIButton is derived from UIControl. This works for object derived from UIControl.

    I wanted to reuse "UIBarButtonItem" action on specific use case. Here, UIBarButtonItem doesn't offer method sendActionsForControlEvents:

    But luckily, UIBarButtonItem has properties for target & action.

     if(notHappy){        
             SEL exit = self.navigationItem.rightBarButtonItem.action;
             id  world = self.navigationItem.rightBarButtonItem.target;
             [world performSelector:exit];
     }
    

    Here, rightBarButtonItem is of type UIBarButtonItem.

提交回复
热议问题