简体   繁体   中英

UIButton not registering on ios7

I have a button, it works as usual on iOS 5 and 6. But on iOS 7 when I press the button the keyboard dismisses, but the method is not called. When I press it second time it works as intended.

Why is that?

Here is the code:

[self.loginButton addTarget:self action:@selector(loginButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

I have the button in UITableView cell.

EDIT:

Here is how I dismiss keyboard at the beginning of this method, but this method is not getting called o iOS7 until the second time I tap on the button.

for (UITextField *field in @[self.loginField, self.passwordField]) {
    if ([field isFirstResponder]) {
        [field resignFirstResponder];
    }
}

I also have gesture recognizer to remove keyboard on tap outside:

UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeKeyboard)];
[self.view addGestureRecognizer:tapper];
tapper.cancelsTouchesInView = NO;

Here is its method:

- (void) removeKeyboard
{
    [self traverseAllSubviewsOfView:self.view withBlock:^(UIView *inView) {
        [inView resignFirstResponder];
    }];
}

Here is what helped me - I set controller as delegate for gesture recognizer and implement following method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    // test if touch is on button
    if ([touch.view isKindOfClass:[UIControl class]]) {
        return NO;
    }
    return YES; // handle the touch
}

Did you check the cancelsTouchesInView property of the gesture recognizer? This property controls if touches are delivered to any underlying views. So settings this to NO should allow the touch to be sent to your button. More detail here.

This property can be set in code or in Interface Builder. You can set it in IB by highlighting the gesture recognizer and uncheck "Cancels Touches in View" (I think) in the Attributes Inspector.

I'm not in front of a Mac currently so I can't confirm the exact wording.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM