• firstresponder 后,键盘不显示


    问题:调用了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.

  • 相关阅读:
    grunt学习(二)——安装grunt及其插件
    grunt学习(一)——nodejs入门
    18个常用的网站性能测试工具
    JSTL(fn函数)
    为MySQL选择合适的备份方式
    Web开发者文档和手册
    为Ruby On Rails开发者准备的5款IDE
    量子统计
    【日常训练】【ACM】2019-10-27_ccpc2019秦皇岛
    poj 2686 Traveling by Stagecoach
  • 原文地址:https://www.cnblogs.com/wyqfighting/p/4057341.html
Copyright © 2020-2023  润新知