开发者

Selector with argument

开发者 https://www.devze.com 2023-02-07 16:35 出处:网络
I have a method like this: - (void)methodWithParameter:(id)parameter { } and I want to call it using an UIBarButtonItem

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 -initWithBa开发者_如何学GorButtonSystemItem:target:action:withObject: method found

can anybody help me with this?


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

精彩评论

暂无评论...
验证码 换一张
取 消