0

I am stuck in a small problem,

I dynamically create a UIBarButtonItem using this code..

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(didSelectPopitDownFromNavBar:)];

self.navigationItem.rightBarButtonItem = rightButton;

and the selector method is this..

-(IBAction)didSelectPopitDownFromNavBar:(id)sender event:(UIEvent *)event

so it gives a crash on click.. how can i pass this event..?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ahmed Z.
  • 2,329
  • 23
  • 52

2 Answers2

5

All of the parameters form part of the method signature, so your button would need to use:

@selector(didSelectPopitDownFromNavBar:event:)

but this probably isn't going to do what you want as the button will only expect to pass itself (as the sender).

Wain
  • 118,658
  • 15
  • 128
  • 151
2

If your function was

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(didSelectPopitDownFromNavBar:)];
...
-(IBAction )didSelectPopitDownFromNavBar:(id)sender

It shouldn't crash, the problem is likely the selector isn't properly defined,

see this question - Passing parameters on button action:@selector

Community
  • 1
  • 1
Dave S
  • 3,378
  • 1
  • 20
  • 34