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.

相關文章
相關標籤/搜索