Programmatically fire button click event?

后端 未结 5 1216
后悔当初
后悔当初 2020-12-04 07:36

Is there a way to programmatically fire a button click event? I have a button placed there in an UIView, and in a particular scenario i want to click the button via code, no

5条回答
  •  旧时难觅i
    2020-12-04 08:29

    I had the same issue as above. I would have posted a comment, but my reputation isn't high enough. So, I will instead post the full answer:

    [btn setHighlighted:YES];
    [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
    [btn performSelector:@selector(setHighlighted:) withObject:NO afterDelay:0.25];
    

    This will programmatically hit the button and highlight it for a seemingly normal amount of time. Richie's suggestion didn't work as the button was only highlighted (if at all) for an imperceptible amount of time.

提交回复
热议问题