开发者

simple question about UITextField and not working secureTextEntry

I have a password field with text "Password" and when user clicks, it gets cleared. Moreover I want to set the type of this textfield as secure but this doesn´t work.

- (void)textFieldDidBeginEditing:(UITextField *)textField{

  if ([开发者_如何学编程textField.text isEqualToString:@"Password"] || [textField.text isEqualToString:@"Email"])
  {
  textField.text = @"";
      textField.secureTextEntry = YES;
  }
}


I've just had the same problem. I was changing the property from within the textFieldDidBeginEditing: call.

Moving the property change to the textFieldShouldBeginEditing: call fixed the problem. I believe the trick is to change it while the text field isn't the becomeFirstResponder.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if ([textField isEqual:_passwordField]) {
        textField.secureTextEntry = YES;
    }

    return YES;
}


Simply put your text in a placeholder and make your password textfield secure. Your problem will be solved :).


- (void)textFieldDidBeginEditing:(UITextField *)textField{

  if ([textField.text isEqualToString:@"Password"] || [textField.text isEqualToString:@"Email"])
  {
  textField.text = @"";
    [textField resignFirstResponder];
    textField.secureTextEntry = YES;
    [textField becomeFirstResponder];
  }
}

it can solve your problem , but it has a big bug. the shit UITextField .


set the property in interface builder or when you initialize textfield remove the line from

-(void)textFieldDidBeginEditing:(UITextField *)textField {
}

I think you should set placeholder text as email or password and pre select the secure text entry from interface builder.That's it...


I realize this is a little old, but in iOS 6 the UITextField "text" is now by default "Attributed" in Interface Builder. Switching this to be "Plain", which is how it was in iOS 5, fixes this problem.


If your keyboard is present, secureTextEntry won't work. Because the UITextInputTraits Protocol doesn't change the textfield if the keyboard shows. You can dismiss the keyboard, and it will work

[myTextField resignFirstResponder]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜