我有一个按钮,它在 iOS 5 和 6 上照常工作。但是在 iOS 7 上,当我按下按钮时,键盘消失,但没有调用该方法。当我第二次按下它时,它会按预期工作。
这是为什么?
代码如下:
[self.loginButton addTarget:self action:@selector(loginButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
我在 UITableView 单元格中有按钮。
编辑:
这是我在这个方法的开头关闭键盘的方式,但是直到我第二次点击按钮时,这个方法才会在 iOS7 上被调用。
for (UITextField *field in @[self.loginField, self.passwordField]) {
if ([field isFirstResponder]) {
[field resignFirstResponder];
}
}
我还有手势识别器,可以在外面点击时移除键盘:
UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeKeyboard)];
[self.view addGestureRecognizer:tapper];
tapper.cancelsTouchesInView = NO;
这是它的方法:
- (void) removeKeyboard
{
[self traverseAllSubviewsOfView:self.view withBlock:^(UIView *inView) {
[inView resignFirstResponder];
}];
}
最佳答案
这对我有帮助 - 我将 Controller 设置为手势识别器的委托(delegate)并实现以下方法:
- (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
}
关于ios - UIButton 没有在 ios7 上注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19444468/