firstresponder 后,键盘不显示
2014-10-28 17:17
609 查看
问题:调用了firstresponder ,但键盘并没有显示,必须手动点击一下,才会显示键盘
分析:原入口进入是好的,自己新加了个window,从这个winodw的界面中点击进入就不显示了。
说明界面本身并没有问题,是自己新加的window导致了键盘弹不出
怀疑:
1、优先级
排除,因为如果是优先级的问题,点击触发也不会弹出
2、自己新建的窗口的界面中,没有释放掉firstResponder,导致UITextField获得不了
将自己窗口的界面中,所有界面元素在界面willdisappear的时候都显示调用一下resignFirstResponder,依然无效,排除
想不出别的原因了,google之,没找到好的解决办法,基本都是由于2,但看到了一些方法,如用
canbecomeFirstResponder来判断当前view能否获得firstResponder.
测试了下我的UITextField,果然返回no,为什么了?为什么这个view不能成为第一响应者,不应该啊!
https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html#//apple_ref/doc/uid/TP40009541-CH4-SW1
看了下响应链,意外发现:
Note: Make sure that your app has established its object graph before assigning an object to be the first responder. For example, you typically call the becomeFirstResponder method in an override of the viewDidAppear: method. If you try to assign the first responder in viewWillAppear:, your object graph is not yet established, so the becomeFirstResponder method returns NO.
也就是说,我们应当最好在viewDidAppear中设置第一响应者。
最终发觉,它不能成为第一响应者,还是由于入口window的问题。
原因:我新建了一个window,把这个界面push进来,但是我并没有把这个window设为keywindow,导致它在响应链的位置有变化,所以不能成为第一响应者。
解决:1、保存原来的keywindow 2、在这个新window显示时,把它设为keyWindow 3、在它消失时,将原来的keywindow设回,ok.
分析:原入口进入是好的,自己新加了个window,从这个winodw的界面中点击进入就不显示了。
说明界面本身并没有问题,是自己新加的window导致了键盘弹不出
怀疑:
1、优先级
排除,因为如果是优先级的问题,点击触发也不会弹出
2、自己新建的窗口的界面中,没有释放掉firstResponder,导致UITextField获得不了
将自己窗口的界面中,所有界面元素在界面willdisappear的时候都显示调用一下resignFirstResponder,依然无效,排除
想不出别的原因了,google之,没找到好的解决办法,基本都是由于2,但看到了一些方法,如用
canbecomeFirstResponder来判断当前view能否获得firstResponder.
测试了下我的UITextField,果然返回no,为什么了?为什么这个view不能成为第一响应者,不应该啊!
https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html#//apple_ref/doc/uid/TP40009541-CH4-SW1
看了下响应链,意外发现:
Note: Make sure that your app has established its object graph before assigning an object to be the first responder. For example, you typically call the becomeFirstResponder method in an override of the viewDidAppear: method. If you try to assign the first responder in viewWillAppear:, your object graph is not yet established, so the becomeFirstResponder method returns NO.
也就是说,我们应当最好在viewDidAppear中设置第一响应者。
最终发觉,它不能成为第一响应者,还是由于入口window的问题。
原因:我新建了一个window,把这个界面push进来,但是我并没有把这个window设为keywindow,导致它在响应链的位置有变化,所以不能成为第一响应者。
解决:1、保存原来的keywindow 2、在这个新window显示时,把它设为keyWindow 3、在它消失时,将原来的keywindow设回,ok.
相关文章推荐
- Xcode6.0下,UItextfield成为FirstResponder无法呼出键盘的解决
- UISearchController自动弹出键盘,调用becomeFirstResponder变为第一响应事件
- becomeFirstResponder无法调起键盘
- first responder与小键盘之间的关系
- becomeFirstResponder 不弹出键盘
- IOS 获取文本焦点 主动召唤出键盘(becomeFirstResponder) and 失去焦点(退下键盘)
- UITextfield resignFirstResponder键盘不回收
- becomeFirstResponder 不弹出键盘
- ios 使用 resignFirstResponder 无法hide键盘
- ,随便点击屏幕任何位子都可以resignFirstResponder,隐藏键盘的两种方法
- 数码管显示矩阵键盘扫描程序
- UI: 使用 UITextView 显示多行文本(有键盘处理)
- EdtText默认显示数字键盘,不强制输入数字
- 键盘输入字母显示数字的问题 ——FN键的特殊应用
- 写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”);
- 手动显示光标及软键盘
- canBecomeFirstResponder
- 理解xib(nib)、File’s Owner、First Responder、outlet、action等概念
- iOS学习笔记6 - 第一响应对象初涉(First Responder)
- Qt iOS端键盘光标显示异常