我有一個UITextField在橫向視圖中,當我按下'解僱鍵盤'按鈕在UIKeyboard視圖的右下角,鍵盤不會消失。有沒有辦法以編程方式監聽該按鍵何時被按下?還是有沒有連接,我沒有看到這會使這個鍵盤消失? 這是iOS 4和XCode 4.謝謝。iPad的'解僱鍵盤'按鈕並沒有關閉鍵盤
回答
今天我有同樣的問題,我想知道它是否適用於Apple的KeyboardAccessory示例代碼。 所以我做了逆向工程。 ViewController並不是我在我的案例中犯的錯誤。
在UIApplicationDelegate的實現中,有應用程序的入口點,其中根視圖控制器和窗口將被設置爲- (void) applicationDidFinishLaunching:(UIApplication *)application
。如果您忘記將作爲子視圖的根視圖控制器視圖添加到窗口,那麼在應用程序的任何視圖中,dismiss-keyboard-button都不起作用。
@class ViewController;
@interface KeyboardAccessoryAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ViewController *viewController;
@end
...
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
請不要忘記設置在主XIB文件的網點。
我不知道爲什麼這與鍵盤行爲有關。但我的理論是,響應者鏈與窗口沒有聯繫,但它需要。
您需要告訴接受鍵盤輸入的文本字段不再是第一響應者。
[UITextField resignFirstRepsonder];
要使用關閉鍵盤按鈕關閉該鍵盤需要實現委託方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//Check if your text field is first responder, and if it is, have it resign
}
另外,如果你想關閉該鍵盤通過點擊它的外部,請
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIView* view in self.view.subviews)
{
if ([view isKindOfClass:[UITextField class]]) {
[view resignFirstResponder];
}
if ([view isKindOfClass:[UITextView class]]) {
[view resignFirstResponder];
}
}
}
謝謝@capt kettch - 我已經在我的代碼中有這個...這裏是一個片段...我有類設置爲UITextField的委託:'@interface SettingsController:UIViewController
我忘了提及,你應該確保你的文本字段的委託設置爲viewcontroller(很可能是self) – 2011-06-21 21:55:59
- 1. 取消按鈕解僱的UISearchBar鍵盤
- 2. 關閉IPAD上的鍵盤
- 3. 我如何解僱鍵盤上關於UISearchBar的鍵盤上的搜索按鈕?
- 4. iPad popover textfield - resignFirstResponder不會解僱鍵盤
- 5. IPad鍵盤「隱藏按鈕」
- 6. 鍵盤解僱沒有工作在Android
- 7. 解僱鍵盤FirstResponder問題
- 8. 的iPad - 關閉鍵盤在UIModalPresentationFormSheet模式
- 9. 關閉鍵盤數字鍵盤
- 10. 我可以刪除iPad鍵盤'隱藏鍵盤'按鈕嗎?
- 11. 檢測iPad的鍵盤隱藏按鈕
- 12. UIKeyboardTypeNumberPad關閉鍵盤
- 13. Android關閉鍵盤
- 14. MFMessageComposeViewController關閉鍵盤
- 15. 關閉iphone鍵盤
- 16. 鍵盤並沒有解僱,如果我使用模態segue
- 17. 當點擊數字鍵盤關閉鍵盤,並把號碼
- 18. 添加IPad鍵盤的按鍵
- 19. 軟鍵盤按鈕
- 20. iPhone - 用OK按鈕關閉鍵盤,用UITextView接受返回鍵
- 21. UITextField控制關閉按鈕和鍵盤返回鍵
- 22. UITextField iOS:如何處理解僱鍵盤按鈕?
- 23. 關閉textview的鍵盤
- 24. 安卓鍵盤向後按關閉
- 25. ResignFirstResponder不關閉鍵盤(iPhone)
- 26. MonoTouch關閉鍵盤(各種)
- 27. windows 7 phone - 關閉鍵盤
- 28. applicationWillResignActive關閉鍵盤iPhone
- 29. 使用鍵盤關閉JFrame
- 30. Framework7 - SearchBar關閉鍵盤
是的 - 這不是問題。該消息發送時鍵盤消失。問題是,當按下iPad鍵盤右下方的「解除鍵盤」按鈕(看起來像是一個小鍵盤圖標)時,沒有任何反應。而文本字段沒有收到來自該鍵的任何輸入。我真的很想知道我現在是否遇到過錯誤。不過謝謝。 – 2011-05-28 04:18:45