views:

2075

answers:

2

I have a pretty simple UIViewController. It's initialized with a view I've created in Interaface Builder, which contains only a UIImageView. When the user touches the screen, I want the touchesBegan message of UIViewController to get called. So, I override it and added some logging, but nothing has happened.

I haven't done anything "special" at all, as since UIViewController inherits from UIResponder, I expect this to work right out of the box. From what I understand UIImageViews have user interaction disabled by default, so I have enabled it, both via InterfaceBuilder and in my UIViewcontroller's viewDidLoad method (I have tied the UIImageView to an IBOutlet). I also am ensuring that userInteraction is enabled in the parent view in Interface Builder.

Anything else that I am forgetting here?

+1  A: 

It is hard to say what your problem is, I don't know what you mean by overriding it?

Make sure you are connecting the touchesBegan event with an IBAction in Interface Builder?

You must create a IBAction function to handle the event, and explicitly connect the even to the IBAction. It is not as simple as simply overriding a method.

Although you have the View tied to an IBOutlet, you need to connect the event using an IBAction, or else you won't get any of those events.

Kekoa
+1  A: 

OK, I'm a dummy. It works fine. The problem was, I didn't realize I was sending a release message to the UIViewController without having retained it elsewhere first. So that was causing the problem.

bpapa