iPad'关闭键盘'按钮不会消除键盘 [英] iPad 'dismiss keyboard' button doesn't dismiss keyboard

查看:140
本文介绍了iPad'关闭键盘'按钮不会消除键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在横向视图中有一个UITextField,当我按下UIKeyboard视图右下方的关闭键盘按钮时,键盘不会消失。有没有办法以编程方式侦听按下此键的时间?或者是否有一个我没看到的连接会使这个键盘消失?
这是iOS 4和XCode 4.谢谢。

I have a UITextField in a Landscape view, and when I press the 'dismiss keyboard' button in the lower right of the UIKeyboard view, the keyboard does NOT disappear. Is there a way to programmatically listen for when this key was pressed? Or is there a connection I am not seeing that will make this keyboard go away? This is iOS 4 and XCode 4. Thanks.

推荐答案

今天我遇到了同样的问题,我想知道,不管它适用于Apple的KeyboardAccessory示例代码。
所以我做了逆向工程。 ViewController不是我在我的情况下犯的错误。

I had same problem today and I wondered, wy it works in Apple's KeyboardAccessory Sample Code. So I did reverse engineering. The ViewController was not the mistake I made in my case.

在UIApplicationDelegate的实现中有应用程序的入口点,其中root viewcontroller和window将被设置为 - (void)applicationDidFinishLaunching:(UIApplication *)application 。如果您忘记将root viewcontrollers视图添加到窗口作为子视图,则dismiss-keyboard-button将无法在您应用的任何视图中使用。

In the implementation of UIApplicationDelegate there is the entry point of application, where root viewcontroller and window will be setup - (void) applicationDidFinishLaunching:(UIApplication *)application. If you forgot to add root viewcontrollers view to window as subview, the dismiss-keyboard-button wouldn't work in any view of your app.

@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文件中设置插座。

Please don't forget to setup the outlets in the main xib file.

我不知道为什么这与键盘行为有关。但我的理论是,响应者链没有链接到窗口,但它需要。

I dont know why this is related to keyboards behavior. But my theory is, that the responder chain is not linked to window, but it needs.

这篇关于iPad'关闭键盘'按钮不会消除键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆