I’ve read the apple docs on the responder chain and needed to know: How is it do i NSLog the object that was tapped on?
Let’s say I have a very complex view controller with multiple views object, when ever i tap on an object (UIButton or what ever..) is there a way to know that particular object that was tapped on?
The docs gave a good overview, but wasnt to clear in methods to overwrite.
EDIT:
The situation is in testing different apps i have not written. I need a quick way to determine the Object that was tapped on (as many apps have custom controls/object that looks like one thing, but is really another). I was hoping there was some way to intercept the touch event right as it was being sent to UIAppication, and then NSLog it.
You can override
-[UIApplication sendAction:to:from:forEvent]to do what you want:Put that in a custom subclass of UIApplication. Then, in main.m, change the call to
UIApplicationMain()so that your custom subclass is used:Note that this only works for UIControl subclasses, which send their actions to their targets using this mechanism. If you want to see all touch events going through an app, override
-[UIApplication sendEvent:]instead. In that case, it will be up to you to figure out which object is going to receive the touch. You can do that with by calling-hitTest:on your main view/window, though keep in mind that that figures out which view the touch lands on, not necessarily which view handles it (views can forward events to other objects, for example). Something like this: