user396004
user396004

Reputation: 285

UIViewController subclass not receiving touchesBegan iphone ipad

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.

Upvotes: 2

Views: 10261

Answers (4)

progrmr
progrmr

Reputation: 77191

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.

Upvotes: 6

MishieMoo
MishieMoo

Reputation: 6680

If you change your VC's view to a UIControl (UIControl is the superclass of a UIView) in IB, you can assign it an IBAction. You can have your textfield resignFirstResponder in that action.

Upvotes: 1

TheSquad
TheSquad

Reputation: 7506

Is the UIView you are talking about is one you have created, or are you using the one furnished with the UIViewController ? Further more, if the click happen on the UITableView, you will have to subclass this to let your UIViewController know that a click occurred on the tableview...

Upvotes: 0

Jerry Jones
Jerry Jones

Reputation: 5403

Unfortunately, touchesBegan only takes place in the view, despite UIViewController being a subclass of UIReponder. The docs for touchesBegan say this.

Tells the receiver when one or more fingers touch down in a view or window.

Upvotes: 0

Related Questions