Touches which object
This may seems simple for you but I would like to know which object is being touched on a view...
I explain...in the viewDidLoad method, I have several objects which are created programmatically (uiimageviews, labels, buttons, etc).
Now in the touchesEnded method, I would like to know which object has been single tapped...how to?
I tried [touch self] == UIImageView开发者_JAVA百科], but it's not working...
Thanks
The - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
callback provides the information you need the touches
parameter. To extract the view that got the touch use:
UIView *touchedView = [[touches anyObject] view];
You can then compare:
if (myView == touchedView) {
// do stuff
}
More info at developer.apple.com
精彩评论