views:

626

answers:

2

How can I detect touches in a UIviewController for a UIView with code only (without Interface Builder)?

I found the touchesBegan method but it doesn't get called ever. I didn't initialize anything else regarding this method. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

+1  A: 

I would read over the Touch Events sections of the iPhone Application Programming Guide.

UIViewController and UIView are both UIResponders, which is responsible for handling the events.

To handle events, you need to override the touch* methods to do what you want. To know what kind of touch events occurred, look at the UIEvent.

Ben S
A: 

In your init method:

self.userInteractionEnabled = YES;
Ian Henry