If you set the target in the NSObject class the action will not work. SO you have to add the codes in the ViewController.m class then it will work .
Setting target to be the NSObject
-
06-08-2022 - |
Question
I have an NSObject
that creates an UIImageView
. I add gesture recognizers to the UIImageView
but the target is not set to the class itself. I would like to know how to do this.
//inside the init method of the NSObject:
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.numberOfTapsRequired = 2;
[theImage addGestureRecognizer:tapRecognizer];
//this method is directly beneath the init method of the NSObject, I want this
//to be called when the image is double tapped
- (void)handleTap:(UITapGestureRecognizer*)recognizer
{
}
So what is it I need to set initWithTarget: to? it is not self
because this crashes the app, yielding a bad access error
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow