2012-02-17 36 views
2

我正在使用iOSOpenDev爲通知中心做一個應用程序。我在UIView上有一個UITextField,並且已經實現了UITextFieldDelegate協議。爲什麼iOS 5 WeeApp中沒有UITextField清除按鈕?

我的問題是textFieldShouldClear方法永遠不會被點擊UITextField中的清除按鈕調用。其他接口方法,如shouldChangeCharactersInRange和textFieldShouldReturn被調用沒有問題。

任何想法爲什麼界面方法永遠不會被調用?

回答

0

確保文本框的委託是自:

theTextField.delegate = self; 

我聽說UIActionSheet吸了UITextFieldDelegate協議,並通知中心可能會做同樣的...

+0

textField的委託已經設置爲self,但它沒有區別。 – icecreamhead 2012-03-01 00:02:42

+0

找到任何更改UITextfield委託(除了將其設置爲self的委託)並將其註釋掉的內容。然後看看它是否有效。我會使用寫入文件的東西,因爲NSLog很難處理您的情況。 – 2012-04-17 11:48:10

1

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

繼格雷厄姆心動的回答,我改變了我的resignFirstResponder呼籲:

[self.focusInput performSelector: @selector(resignFirstResponder) 
         withObject: nil 
         afterDelay: 0.2f]; 

現在鍵盤會按照預期自動隱藏在水龍頭上,但清除按鈕功能已恢復。