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?

+3
source share
1 answer

This does not work. You cannot pass a parameter to an action. An action method always has:

  • no argument whatsoever
  • one argument (id)sender,
  • or two arguments (id)senderand (UIEvent *)event.
+4
source

Source: https://habr.com/ru/post/1788705/


All Articles