2012-04-20 70 views
0

我有兩個Custom Cells一個UITableView。其中Custom Cells包含一個UITextField自定義的UITableViewCell + resignFirstResponder

我在與按下返回按鈕時隱藏鍵盤問題。

- (IBAction)textFieldDoneEditing:(id)sender { 
    [sender resignFirstResponder]; 
    } 

通常我會用這個,但它永遠不會被調用。我將它與Editing Did End事件連接起來。

是因爲我使用Custom Cell

+0

有你設置的文本字段代表?該方法被稱爲textFieldDidEndEditing: – Otium 2012-04-20 01:20:12

+0

是的。我設置了文本字段的代表。我想這就是爲什麼它不起作用。 – Backslash 2012-04-20 01:23:52

回答

1

無需連線了一個IBAction爲。使用委託方法(我也將IB中的返回鍵更改爲完成,以使其對用戶更加明顯)。確保您已將文本字段的委託連接到您的VC類。

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    // Dismiss the keyboard when the Return key is pressed. 
    [textField resignFirstResponder]; 

    return YES; 
} 
+0

謝謝!現在工作:) – Backslash 2012-04-20 01:53:30