Passing parameters in self action:@selector

2019-07-18 05:31发布

问题:

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:)];