我有这个问题当用户在屏幕上的其他地方点击时我解散键盘。我有一个手势识别器来查找点击,当检测到点击时,它会在文本字段中调用resignFirstResponder。不幸的是,这打破了清晰的按钮。
我所做的就是过滤水龙头以确保它们是表视图外,具有手动触发按钮,水龙头稍微复杂:
// In: - (void)handleTap:(UITapGestureRecognizer *)sender {
// The user tapped outside a text field, drop the keyboard.
// Unfortunately this normally breaks the clear button, so we'll check that the
// tap is outside the table view (and therefore not on a clear button).
BOOL inButton = CGRectContainsPoint(self.signInButton.bounds, [sender locationInView:self.signInButton]);
BOOL inTable = CGRectContainsPoint(self.tableView.bounds, [sender locationInView:self.tableView]);
if (!inTable && !inButton) {
BOOL didEndEditing = [self.view endEditing:NO];
// But... if we were editing a field (& therefore the keyboard is showing),
// and if they tapped the sign in button, sign in. Not sure where the
// onSignIn event is getting lost. The button does highlight. But the
// call to endEditing seems to eat it.
if (didEndEditing && inButton) {
[self onSignIn:self.signInButton];
}
}
textField的委托已经设置为self,但它没有区别。 – icecreamhead 2012-03-01 00:02:42
找到任何更改UITextfield委托(除了将其设置为self的委托)并将其注释掉的内容。然后看看它是否有效。我会使用写入文件的东西,因为NSLog很难处理您的情况。 – 2012-04-17 11:48:10