سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top