Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fire uibarbuttonitem click event programmatically

I have created a UIActionSheet

UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@""
                                                              delegate:self
                                                     cancelButtonTitle: @"cancel"
                                                destructiveButtonTitle: @"OK"
                                                     otherButtonTitles: nil];
          [action showInView:self.view];
          [action release];

On the event of the cancel button in the UIActionSheet I want to fire the event of a UIBarButtonItem, which is in my view.

My question is how can I fire the button event(without touching the button) in the UIActionSheet delegate method

like image 313
Jean Paul Scott Avatar asked Feb 29 '12 09:02

Jean Paul Scott


2 Answers

Another way to do that and avoiding warnings is as follows:

[[UIApplication sharedApplication] sendAction:barButtonItem.action
                                           to:barButtonItem.target
                                         from:nil
                                     forEvent:nil];
like image 185
Antonio Carlos Avatar answered Sep 25 '22 09:09

Antonio Carlos


Not knowing the current bar button item action you can invoke it this way:

[barButtonItem.target performSelector:barButtonItem.action]

This will however bring "unknown selector" compiler warning, but this may be worked around.

like image 32
ayoy Avatar answered Sep 22 '22 09:09

ayoy