简体   繁体   English

关于 UITextField 和不工作的简单问题 secureTextEntry

[英]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.我正在从textFieldDidBeginEditing:调用中更改属性。

Moving the property change to the textFieldShouldBeginEditing: call fixed the problem.将属性更改移动到textFieldShouldBeginEditing:调用解决了问题。 I believe the trick is to change it while the text field isn't the becomeFirstResponder .我相信诀窍是在文本字段不是becomeFirstResponder时更改它。

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

    return YES;
}
- (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.狗屎UITextField。

Simply put your text in a placeholder and make your password textfield secure.只需将您的文本放在一个占位符中,并使您的密码文本字段安全。 Your problem will be solved:).您的问题将得到解决:)。

I realize this is a little old, but in iOS 6 the UITextField "text" is now by default "Attributed" in Interface Builder.我意识到这有点老了,但在 iOS 6 中,UITextField “文本”现在在界面生成器中默认为“属性”。 Switching this to be "Plain", which is how it was in iOS 5, fixes this problem.将其切换为“普通”,这就是它在 iOS 5 中的方式,解决了这个问题。

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...我认为您应该将占位符文本设置为 email 或密码,并在 select 之前设置来自界面生成器的安全文本条目。就是这样...

If your keyboard is present, secureTextEntry won't work.如果您的键盘存在, secureTextEntry将不起作用。 Because the UITextInputTraits Protocol doesn't change the textfield if the keyboard shows.因为如果键盘显示, UITextInputTraits协议不会更改textfield You can dismiss the keyboard, and it will work你可以关闭键盘,它会工作

[myTextField resignFirstResponder]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM