views:

266

answers:

1

I'm sure this is an easy one, yet I need some pointing in the right direction. I have a rather complicated NIB that I would like to have only one view in that nib to listen for touch & multi-touch events. What is the best way of doing so using IBOutlets?

Thanks

A: 

If I were you, I would do the following: subclass UIView and implement whichever of the UIResponder touch methods are useful to you:

– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:

Or you could implement these methods in a UIViewController subclass.

Jonathan Sterling
Thanks. Sounds doable, but what are the implications of subclassing a UIView that is already being loaded from the nib?
Jonathan Dumaine
That should be just fine. Just make sure that the nib knows the custom class of your UIView. UIViews (and NSViews) in nibs are generally meant to be instances of a subclass, because a UIView (or NSView) doesn't do a whole lot on its own. Good luck!
Jonathan Sterling
How do you subclass a UIView defined in a nib file?
bentford
What you want to do is write your own subclass, like `EpicJusticeView.h`, `EpicJusticeVice.m`. Then, in your nib file, go to the inspector for your UIView instance, and change it's class to `EpicJusticeView`.
Jonathan Sterling