Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

adildacoolset

macrumors 65816
Original poster
I'm trying to detect a touch in a UIImageView. I'm trying to make it such that if a user taps on an image, it wil call a method, and if a user taps on another, it will call another method. Here is my code so far:

Code:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch* touch = [touches anyObject];
    
    if ([touch view] == self.imageView1){
        [self doAMethod];
        NSLog(@"Touched!");
    }
    else if ([touch view] == self.imageView2){ 
        [self doAnotherMethod];
    }
    else if ([touch view] == self.imageView3){
        [self doYetAnotherMethod];
    }
    else if([touch view] == self.imageView4){
        [self doADifferentMethod];
    }
}
Just to let you know, I ticked the userInteractionEnabled box for the images in the IB.

So far, it doesn't work. Please help. Even the
Code:
NSLog
statement does not do anything, signifying that it didn't respond to the touch at all.
 
Try putting an NSLog (or better yet, a breakpoint) before your conditionals, to verify your touchesBegan: is being called at all.
 
The UIResponder touches methods are not used much anymore. What you describe sounds like a button. If so then use a button with an image. Otherwise use a UIGestureRecognizer for this.

Using buttons or gesture recognizers will make this task simpler.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.