I have a UIViewController that contai开发者_JS百科ns 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 a UIView
method, not a UIViewController
method. What are you trying to achieve here? You should very seldom have a UI reaction to touchesBegan:
. You probably mean to use UITapGestureRecognizer
instead.
Make sure to use accessors (self.scrollView
) rather than accessing your ivars directly. Direct ivar access is the #1 cause of memory management crashes.
精彩评论