質問

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