【问题标题】:How to set the touch down event of UITextField programmatically in iPhone如何在 iPhone 中以编程方式设置 UITextField 的触摸事件
【发布时间】:2019-04-30 23:30:17
【问题描述】:

我有一个以编程方式添加的 UITextField。 我想设置该 UITextField 的触摸事件,即当用户第二次单击文本字段时,它应该退出第一响应者。这意味着键盘应该消失。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    UITextField 继承自 UIControl,因此您应该能够通过实现 touchesBegan: 并检查 UITextField 是否已经是 firstResponder 来做您想做的事情。如果是,只需向 UITextField 对象发送 resignFirstResponder 消息。

    【讨论】:

      【解决方案2】:

      你可以试试这样的

      [passwordTextField addTarget:self action:@selector(textEditingStarted:)forControlEvents:UIControlEventEditingDidBegin];

      -(void)textEditingStarted:(UITextField*)sender{ ENTER_METHOD; }

      【讨论】:

        猜你喜欢
        • 2014-07-17
        • 1970-01-01
        • 1970-01-01
        • 2019-05-10
        • 2011-05-01
        • 2013-09-16
        • 1970-01-01
        • 2011-01-01
        • 1970-01-01
        相关资源
        最近更新 更多