开发者

Why isn't my UIViewController responding to touches?

开发者 https://www.devze.com 2023-04-04 16:02 出处:网络
I have a UIViewController that contai开发者_JS百科ns a UIScrollView, which has a UIView inside of its contentview.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消