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开发者_StackOverflow 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.
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.
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.
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.
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...
精彩评论