firstresponder 后,键盘不显示

问题:调用了firstresponder ,但键盘并无显示,必须手动点击一下,才会显示键盘html

 

分析:原入口进入是好的,本身新加了个window,从这个winodw的界面中点击进入就不显示了。ios

说明界面自己并无问题,是本身新加的window致使了键盘弹不出app

 

怀疑:ide

一、优先级测试

    排除,由于若是是优先级的问题,点击触发也不会弹出ui

二、本身新建的窗口的界面中,没有释放掉firstResponder,致使UITextField得到不了google

    将本身窗口的界面中,全部界面元素在界面willdisappear的时候都显示调用一下resignFirstResponder,依然无效,排除spa

 

想不出别的缘由了,google之,没找到好的解决办法,基本都是因为2,但看到了一些方法,如用htm

canbecomeFirstResponder来判断当前view可否得到firstResponder.it

 

测试了下个人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,致使它在响应链的位置有变化,因此不能成为第一响应者。

解决:一、保存原来的keywindow   二、在这个新window显示时,把它设为keyWindow   三、在它消失时,将原来的keywindow设回,ok.

相关文章
相关标签/搜索