0

What is the delegate method called when rightBarButtonItem of UIBarButtonItem is tapped? I want to implement a specific action there.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Abhinav
  • 37,684
  • 43
  • 191
  • 309

2 Answers2

3

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:

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Mark"                               style:UIBarButtonItemStylePlain  target:self action:@selector(actionForTap:) autorelease];

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.:

self.navigationItem.rightBarButtonItem.target = self;
self.navigationItem.rightBarButtonItem.action = @selector(actionForTap:);

As a third way, you can configure it in IB (but I'm not going there).

matt3141
  • 4,303
  • 1
  • 19
  • 24
fsaint
  • 8,759
  • 3
  • 36
  • 48
0

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;
Mgamerz
  • 2,872
  • 2
  • 27
  • 48
Ashvin
  • 8,227
  • 3
  • 36
  • 53