Selector with argument

邮差的信 提交于 2019-12-12 14:52:38

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/4838515/selector-with-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!