Question

Is it possible to make category on UITapGestureRecognizer? I want to make convenience method to avoid (alloc-init) game.

I tired this:

+(void)tapDetector :(sel)selectormethod tags:(int)tag :tapsRequired:(int)taps{
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:@selector(??????????????????:)];
    singleTap.numberOfTapsRequired = tag;
    singleTap.numberOfTouchesRequired = tag;   
}

But problem is that I cant get selectorMethod as a action parameter... Can anyone help in this regard?

Was it helpful?

Solution

The selector type is SEL (not sel), and you can pass it directly as the action (no "@selector..." stuff. Eg:

UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:selectormethod];

@selector(...) is a compiler directive that uses the compile-time symbol information to convert the string version of a selector into a constant SEL selector reference for use at runtime. In your case, the caller would be doing that work, and the resulting value can be then passed around.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top