Pergunta

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

Foi útil?

Solução

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 .

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top