我有一個定製的UIAlertView.I,該AlertView中有一個UITextField,一旦顯示,它就成爲第一個響應者。現在,當用戶觸摸AlertView中的其他位置時,我需要關閉該UITextField的鍵盤。我已經爲此接觸了事件。在UIAlertView中關閉UITextField的鍵盤
一切都很到位並且工作正常,除非我在UITextField上調用resignFirstResponder時,它將從第一響應者辭職,但鍵盤不會被解除。有什麼辦法可以解僱那個鍵盤嗎?
我一直在尋找的解決方案,並發現了一個類似的帖子here沒有答案
如果有人能找到一條出路請讓我知道。我甚至嘗試了以下方法,但它不能正常工作
UIWindow* tempWindow;
// Because we cant get access to the UIKeyboard throught the SDK we will just use UIView.
// UIKeyboard is a subclass of UIView anyways
UIView* keyboard;
// Check each window in our application
for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; C++)
{
// Get a reference of the current window
tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
// Get a reference to the current view
keyboard = [tempWindow.subviews objectAtIndex:i];
// Loop through all views in the current window
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
[keyboard removeFromSuperview];
}
}
}
這真的幫助!謝謝! – hawshy 2012-03-02 09:37:03
無論如何有多少firstResponders? – 2012-11-13 11:05:45