2013-08-22 113 views
1

我正在爲iPhone和iPad創建一個iOS應用程序,我的一些屏幕上有一些UITextFields。當用戶點擊文本框時,我想讓鍵盤解散。要做到這一點,我寫了下面的代碼:關閉iPad鍵盤

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    [firstName resignFirstResponder]; 
    [lastName resignFirstResponder]; 
    [email resignFirstResponder]; 
    [password resignFirstResponder]; 
    [retypePassword resignFirstResponder]; 
} 

這適用於iPhone的罰款,但它不適用於iPad上的鍵盤。我在網上搜索和所有sugeestions不起作用。主要建議是:

- (BOOL)disablesAutomaticKeyboardDismissal { 
     return NO; 
} 

但是,這仍然行不通? 任何幫助將不勝感激。

+0

您的控制器如何顯示?如果它以模態形式呈現爲表單,那麼當表單發生這種情況時,iOS有時不允許您解除鍵盤。它只是爲了更好的行爲。 –

+0

您是否確定變量與IB中的iPad視圖相關聯(如果您正在使用它)? – Daniel

+0

@GeorgeGreen - 是的,我正在使用表格進行模態展示。感謝您的解釋。有沒有辦法解決?無法理解爲什麼它適用於iPhone而不適用於iPad –

回答

-1
Add this method to .h file, 
-(IBAction)fn_resign:(id)sender; 


Inherit your XIB to UIControl and just add following method to the view. 

And in file's owner assign this method to view. 

in .m: 
-(IBAction)fn_resign:(id)sender{ 
    //Hide you keyboard. 
}