2011-03-29 122 views
4

在iphone上。當我按下uitextfield時,我不想讓鍵盤彈出。uitextfield隱藏鍵盤?

我想要相同的行爲,只是沒有鍵盤。如何在用戶按下uitextfield時隱藏/關閉鍵盤?

回答

7

如果你想完全相同的行爲,沒有鍵盤,嘗試

textfield.inputView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
6

返回否UITextFieldDelegate- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField應該這樣做。

+0

這是愚蠢的,但如何在

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } 

或 駁回鍵盤觸摸視圖中的任何地方我該怎麼辦這個? – user648244 2011-03-29 21:43:25

+3

這很簡單,你的viewController應該是textfield的委託(你可以在界面生成器中做到這一點),然後你只需在你的viewController中實現該函數並返回NO。我希望這有幫助! – 2011-05-16 10:14:46

0

我覺得你可以在委託方法使用

textfield resignFirstResponder

-

(void)textFieldDidBeginEditing:(UITextField *)

textField like這樣的:

-(void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    if (textField == yourTextField){ 
     [yourTextfield resignFirstResponder]; 
    } 
} 
0

使用這種方法通過點擊鍵盤完成按鈕

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 
    return YES; 
}