bpapa
bpapa

Reputation: 21497

UIViewController not receiving touchesBegan message

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?

Upvotes: 3

Views: 7639

Answers (3)

zenchemical
zenchemical

Reputation: 41

Please ignore the first answer. It is, in fact, as easy as overriding the method in the custom view. The most common reason for not receiving touchesBegan is the canBecomeFirstResponder method not being implemented. This is not an IB hookup, these are the standard methods for touch handling.

Upvotes: 0

bpapa
bpapa

Reputation: 21497

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.

Upvotes: 3

Kekoa
Kekoa

Reputation: 28250

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.

Upvotes: 0

Related Questions