开发者

UITextfield clear button

How can I clear the field which currently has the cursor placed inside it?

I have tried:

if(textfield.isEditing)
   textfield.text = @""; 

This works for me, but if I select all 3 fields, and pres开发者_StackOverflow中文版s the 'clear field button' all the fields clear Also instead of isEditing, I have tried to use tags on the UITextfields and do :

if(textfield.tag == 1)
    textfield.text = @"";

but this has the same effect.

How can I solve this problem?


try one or both of these...

textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.clearsOnBeginEditing = YES;

Then add delegate...

- (BOOL)textFieldShouldClear:(UITextField *)textField {
    return YES;
}


Try out this in TextField's Delegate method didBeginEditing:

if ([textfield isFirstResponder]) {
  textfield.text = @"";
}

Hope this helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜