You cannot directly - UIGestureRecognizer know how to issue a call to a selector that takes only one argument. To be completely general, you probably want to go through a block. Apple did not build this, but it is quite easy to add, at least if you want to subclass the gesture recognizers that you want to get around the problem of adding a new property and cleaning it properly, without delving deep into the runtime.
So, for example, (recorded as I go, unverified)
typedef void (^ recogniserBlock)(UIGestureRecognizer *recogniser); @interface UILongPressGestureRecognizerWithBlock : UILongPressGestureRecognizer @property (nonatomic, copy) recogniserBlock block; - (id)initWithBlock:(recogniserBlock)block; @end @implementation UILongPressGestureRecognizerWithBlock @synthesize block; - (id)initWithBlock:(recogniserBlock)aBlock { self = [super initWithTarget:self action:@selector(dispatchBlock:)]; if(self) { self.block = aBlock; } return self; } - (void)dispatchBlock:(UIGestureRecognizer *)recogniser { block(recogniser); } - (void)dealloc { self.block = nil; [super dealloc]; } @end
And then you can just do:
UILongPressGestureRecognizer = [[UILongPressGestureRecognizerWithBlock alloc] initWithBlock:^(UIGestureRecognizer *recogniser) { [someObject relevantSelectorWithRecogniser:recogniser scrollView:relevantScrollView]; }];
Tommy
source share