I have a UIViewController that contains a UIScrollView, which has a UIView inside of its contentview.
I have the following code that does not work, keyboard is not dismissed, why?:
#pragma mark -
#pragma mark Touch Events
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == scrollView || [touch view] == self.view)
{
[usernameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}
}
touchesBegan:withEvent:is aUIViewmethod, not aUIViewControllermethod. What are you trying to achieve here? You should very seldom have a UI reaction totouchesBegan:. You probably mean to useUITapGestureRecognizerinstead.Make sure to use accessors (
self.scrollView) rather than accessing your ivars directly. Direct ivar access is the #1 cause of memory management crashes.