Calling method set as target on UIButton

11,573

Just found out how to do this. Was pretty easy, feel like a noob asking now!

[button sendActionsForControlEvents:UIControlEventTouchUpInside];
Share:
11,573
ingh.am
Author by

ingh.am

Software Developer working in the East Riding of Yorkshire (UK). Computer Science graduate from The University of Hull with first class honours. SOreadytohelp

Updated on June 10, 2022

Comments

  • ingh.am
    ingh.am about 2 years

    If I have a UIButton which has a target set, is there a way to call this method without explicitly calling it?

    For example:

    [newViewController.button addTarget:self action:@selector(MyMethod) forControlEvents:UIControlEventTouchUpInside];
    

    I'm then looking to call this method in newViewController but cannot as MyMethod belongs to the parent view. So I really want to be able to say, just call the method/target on the UIButton button. But how can I do this?

    Thanks