单击uitextfield时,清除按钮键盘正在消失而不是文本 [英] When clicking on uitextfield's clear button keyboard is disappearing not text

查看:123
本文介绍了单击uitextfield时,清除按钮键盘正在消失而不是文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone中,我查看它有 UITextField 。当我点击 UITextField 的清除按钮时键盘正在消失,而不是 UITextField 中的文字。在ipad中,同样正常工作。请建议我,该怎么办?
提前致谢!!

In iPhone,I have view in which it has UITextField .When i click on the clear button of UITextField's keyboard is getting disappear ,not the text in UITextField.In ipad samething is working correctly. Please suggest me, what to do? Thanks in advance!!

推荐答案

只需清除字段resignFirstResponder(如果要隐藏键盘)并返回NO / false

Just clear the field, resignFirstResponder (if you want to hide keyboard) and return NO/false

Note: set Attributes inspector property of UITextField 




清除按钮 - >编辑时出现



so it will display 'X' button while editing in textfield.

// Objective-C

-(BOOL)textFieldShouldClear:(UITextField *)textField
{
    textField.text = @"";
    [textField resignFirstResponder];
    return NO;
}

// Swift

func textFieldShouldClear(textField: UITextField) -> Bool {
    textField.text = ""
    textField.resignFirstResponder()
    return false
}

这篇关于单击uitextfield时,清除按钮键盘正在消失而不是文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆