Passing parameters in self action:@selector

半腔热情 提交于 2020-01-04 12:08:25

问题


I am trying to add a NSIndexpath as parameter to a method through

[self action:@selector(showDetailedImage)];

Is it possible to add an extra parameter(NSIndexPath) to this method?


回答1:


No, you can not pass arguments, you can only show that this selector will take that many numbers of arguments.

If you need to do this, you can create a property and access it from the method showDetailedImage.

However you can use this selector:

[self performSelector:@selector(showDetailedImageIndex:) withObject:objectOfNSIndex];



回答2:


Make a wrapper(another method) say -(void)wrapperMethodOforiginalSelectorMethod; of your now-selector-method say -(void)originalSelectorMethod:(id)argument; and make the wrapper as your new selector which further calls your originalSelectorMethod with your argument.




回答3:


You have to add extra parameter to

ShowDetailedImage:(NSIndexPath *)indexPath

can call [self action:@selector(showDetailedImage:)];



来源:https://stackoverflow.com/questions/15176161/passing-parameters-in-self-actionselector

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