0

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.
    }
}
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • possible duplicate of [How to find out what view a touch event ended at?](http://stackoverflow.com/questions/16328875/how-to-find-out-what-view-a-touch-event-ended-at) – Mike Aug 14 '14 at 23:41
  • besides implementing `touchesBegan` in my UIViewController is there anything more that I need to do? The method is never called. Not even once, and I have NSLog. In storyboard and in code I set `userInteractionEnabled = YES` – Katedral Pillon Aug 15 '14 at 00:12

1 Answers1

1

Try this:

UITouch *touch = (UITouch *)[touches anyObject];
UIView *touchView = touch.view;
AstroCB
  • 12,337
  • 20
  • 57
  • 73
Arash
  • 1,286
  • 1
  • 8
  • 14