Monis Manzoor
Monis Manzoor

Reputation: 183

How can i assign an action to rightbarbuttonitem with an edit style?

I have an edit rightbarbuttonitem in my view in navigation bar. I set it up with the help of storyboard/IB, not programmatically. Now, all i want is to assign an action when the "done" barbuttonitem is pressed (not edit).

Is there a way to achieve it? I tried manually through -(IBAction), but it's not working. Also, i want to perform the action on selected items in UITableView. So if you give me an idea, it would be great.

Upvotes: 0

Views: 1282

Answers (2)

Andrei Filip
Andrei Filip

Reputation: 1143

That button calls the method

- (void)setEditing:(BOOL)editing animated:(BOOL)animated

You can implement it and it will get called everytime your edit/done button gets tapped. All you have to do is check the button's title property to see when it's showing done and when it's showing edit

Upvotes: 3

Suiz Uzcategui
Suiz Uzcategui

Reputation: 145

If you declared your button as an IBOutlet then all you'd need to do is use the synthesised variable on your .m as so:

_yourBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(runMethod)];
self.navigationItem.rightBarButtonItem = _yourBarButton;

Then you'd have to declare your run method:

-(void)runMethod
{
    //do stuff
}

Upvotes: 0

Related Questions