Suppose I have a button that everytime I clicked it will generate a random number of subviews. Is there anyway to detect the subview touched?
Asked
Active
Viewed 45 times
0
-
I already know there's a way that I add all the generated view to an array and do traversing through the array to get the touched view. But, I don't know if there is better solution. – Q.u.a.n.g L. May 30 '13 at 02:24
1 Answers
0
You can make use of touchesBegan method and use the view property of the UITouch instance passed:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//use touch.view property to get the subview touched
}
Remember to set the property userInteractionEnabled to YES in each of your subviews.

Valent Richie
- 5,226
- 1
- 20
- 21