ios - 如何删除或清除 UITextField

标签 ios objective-c iphone swift uitextfield

如何清除 ios 中的文本字段, 如何让文本框删除用户第一次按键时的所有内容?

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{



    if([tfieldDOB.text length] == 4)
    {
        tfieldDOB.text=[NSString stringWithFormat:@"%@/",tfieldDOB.text];
    }
    else if([tfieldDOB.text length]==7)
    {
        tfieldDOB.text=[NSString stringWithFormat:@"%@/",tfieldDOB.text];

    }

    return YES;

}

最佳答案

更改 在编辑时出现 中的文本字段属性清除按钮模式

或者其他选择只使用单行,在你需要添加的地方

yourtextfieldname.text=@"";  //it is used for clear the textfield values 

swift

yourtextfieldname.text=""

或其他方式

 clearField =@"YES";

if([clearField isequaltostring:@"YES"])  //check this line in 
{
    tfieldDOB.text = @"";
    clearField =@"NO";
}

关于ios - 如何删除或清除 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23151808/

相关文章:

iphone - UITableView 的 didSelectRowAtIndexPath 仅每隔一段时间调用一次

ios - 如何将 UTF8String 转换为基于 JSON 的 NSDictionary?

iphone - 无法识别的选择器,委托(delegate)问题

ios - 一部 iPhone 搜索许多 iBeacon

ios - 如何在 iOS 中创建可缩放的时间线?

ios - 没有任何内存问题 - 延迟后重复异步调用方法

iphone - 全屏 View 隐藏导航和标签栏 iphone

ios - Apache Cordova 可以与 Objective-C 混合使用吗?

ios - 核心数据 : Transformable Type in Entity | Fetch Failed

ios - 如何更改 UIImagePicker 中的条形颜色?