Iphone – UIViewController subclass not receiving touchesBegan iphone ipad

ipadiphonesubclasstouchesbeganuiviewcontroller

So I subclassed UIViewController and in the nib I have a UIView, and in it a tableview. It is my understanding that both UIViewController and UIView are subclasses of UIResponder, so they should receive the – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
method.

However, this is not the case, and my view controller subclass is not receiving that method. I'd really like to not subclass the UIView, if that's allright.

I am trying to implement this, but my

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [textfield resignFirstResponder];
}

Is not getting called.

Best Answer

It depends on where you touch. If you touch in the table view the touches are sent to the tableview, not the view controller. If you touch in a textfield that is in your view, the touches are sent to the UITextField itself. If you touch outside the tableview, outside the textfield but in the viewcontrollers' view then the view controller should get those touches.

Related Topic