2014-04-18 102 views
5

如何在IOS清除文本字段, 我怎样才能使一个文本框包装箱中取出在用户第一次按键所有内容吗?如何删除或清除的UITextField

- (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; 

} 
+0

刷新视图 – Petar

+0

打字我们不能清除它之后它会清除文本。 @ pe60t0 – user3331589

+0

如何编辑.. @ pe60t0 – user3331589

回答

10

改变文本框在appears while editing

或其他选择只使用单一的线,你需要添加

[email protected]""; //it is used for clear the textfield values 

斯威夫特

属性清除按钮模式
yourtextfieldname.text="" 

或另一种方式

clearField [email protected]"YES"; 

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

我已经做了,但它不工作.. @ anbu.Karthil – user3331589

+0

或什么是你明确的字段显示 –

+0

假设我键入1990年至1911年/ 11,当我想编辑它然后onl Ÿ最后两位编辑..ie没有完全编辑.. @庵埠 – user3331589

3

实现文本字段的委托方法textFieldShouldBeginEditing:并设置文本为空字符串时,文本字段正要作为编辑。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
    [textField setText:@""]; 
    return YES; 
} 

或者你可以设置文本框的属性clearsOnBeginEditing

[textField setClearsOnBeginEditing:YES]; 

,并在编辑时开始

+0

等待我会检查它.. @ zen – user3331589