What is the delegate method called when rightBarButtonItem of UIBarButtonItem is tapped? I want to implement a specific action there.
Delegate method called for rightBarButtonItem of UIBarButtonItem
5.5k views Asked by Abhinav At
2
There are 2 answers
0
On
You don't need any delegate method. You can simply use the below code. This is code for simply adding a button on the right and adding an action to that button. In my case I called the method named "AddButtonMethod".
UIBarButtonItem *AddButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddButtonMethod:)];
self.navigationItem.rightBarButtonItem = AddButton;
There is no predefined delegate method. You need to set the delegate/action (similar to a UIControl). For example, create the UIBarButtonItem in viewDidLoad the following way:
and implement actionForTap: in your view controller. If you already have the UIBarButtonItem you can set the target/action to those of your desired delegate method, e.g.:
As a third way, you can configure it in IB (but I'm not going there).