我有這個問題當用戶在屏幕上的其他地方點擊時我解散鍵盤。我有一個手勢識別器來查找點擊,當檢測到點擊時,它會在文本字段中調用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