【问题标题】:iOS UITextFlied secureTextEntry not working on iOS 6.1iOS UITextFlied secureTextEntry 在 iOS 6.1 上不起作用
【发布时间】:2014-05-21 12:05:13
【问题描述】:

我已经设置了一个密码字段,并在其下设置了一个UIButton 以将secureTextEntry 切换为YES/NO

以下是我用过的代码。

- (void)viewDidLoad
{
    self.navigationController.navigationBarHidden=YES;
    [_ShowPasswordButtonOutlet setImage:[UIImage imageNamed:@"box.png"] forState:UIControlStateNormal];
    _password.secureTextEntry=YES;
    [super viewDidLoad];
}

- (IBAction)ShowPassword:(id)sender
{
    if ([_ShowPasswordButtonOutlet.imageView.image isEqual:[UIImage imageNamed:@"box.png"]])
    {
        [_ShowPasswordButtonOutlet setImage:[UIImage imageNamed:@"box_tick.png"] forState:UIControlStateNormal];
        _password.secureTextEntry=NO;
    } else if ([_ShowPasswordButtonOutlet.imageView.image isEqual:[UIImage imageNamed:@"box_tick.png"]])
    {
        [_ShowPasswordButtonOutlet setImage:[UIImage imageNamed:@"box.png"] forState:UIControlStateNormal];
        _password.secureTextEntry=YES;
    }
}

上面的代码似乎在 iOS7iOS7.1工作

但在 iOS6.1 中,按钮图像在单击时似乎会发生变化,但 secureTextEntryYESNO 仅工作一次。稍后如果仅单击UIButton,图像会发生变化,secureTextEntry不起作用

它没有显示任何警告或错误!

【问题讨论】:

  • 你在比较IUIImages?不要那样做,使用布尔标志或只检查_password.secureTextEntry。还可以考虑使用 UISwitch` 而不是 UIButton,它有一个状态。同样按照惯例,方法和变量名称以小写字母开头。
  • 好的,我使用布尔标志。谢谢你的信息。

标签: ios objective-c uibutton uitextfield ios6.1


【解决方案1】:

您应该在 iOS6 中将 secureTextEntry 值设置为 YES 之前禁用 UITextField

- (IBAction)ShowPassword:(id)sender
{
    if (_password.secureTextEntry)
    {
         [_ShowPasswordButtonOutlet setImage:[UIImage imageNamed:@"box_tick.png"] forState:UIControlStateNormal];
         _password.secureTextEntry = NO;
    }
    else 
    {
        [_ShowPasswordButtonOutlet setImage:[UIImage imageNamed:@"box.png"] forState:UIControlStateNormal];
        _password.enabled = NO;
        _password.secureTextEntry = YES;
        _password.enabled = YES;
    }
}

【讨论】:

  • 不要比较图像,代替布尔值。
  • 好的。禁用UITextField 有效。我只是想知道为什么这只是在 iOS6.1 和更少的问题,因为它在 iOS7.0 及更高版本中运行良好。
  • @Zaph 你是对的,因为答案不是直接关于那部分,我没有注意它。马上编辑,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-08
  • 2016-07-03
  • 2012-05-29
  • 2015-07-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多