Katedral Pillon
Katedral Pillon

Reputation: 14864

In a touch event, determine which subview was touched

I have a view controller with a number of subviews. When user clicks on the screen, I want to know which child view was touched. Is there a way to determine this?

-(void)touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
    UIView *touchedView = ...
    if(touchedView == self.importantView){
      //do something cool.
    }
}

Upvotes: 0

Views: 76

Answers (1)

Arash
Arash

Reputation: 1316

Try this:

UITouch *touch = (UITouch *)[touches anyObject];
UIView *touchView = touch.view;

Upvotes: 1

Related Questions