Ahmed Z.
Ahmed Z.

Reputation: 2337

UiBarButtonItem selector.. on click crash

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

Upvotes: 0

Views: 372

Answers (2)

Dave S
Dave S

Reputation: 3468

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

Upvotes: 2

Wain
Wain

Reputation: 119031

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

Upvotes: 5

Related Questions