Skullhouseapps
Skullhouseapps

Reputation: 496

Selector with argument

I have a method like this:


- (void)methodWithParameter:(id)parameter {

}

and I want to call it using an UIBarButtonItem

barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(methodWithParameter:)];
I want to specify the parameter but I can't use withObject: after action: because I get a warning:

No -initWithBarButtonSystemItem:target:action:withObject: method found

can anybody help me with this?

Upvotes: 3

Views: 2819

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135550

It doesn't work that way. You cannot pass a parameter to an action. An action method will always have either:

  • no arguments at all,
  • one argument (id)sender,
  • or two arguments (id)sender and (UIEvent *)event.

Upvotes: 4

Related Questions