iOS UITextFlied secureTextEntry在iOS 6.1上不工作
我已经设置了一个密码字段,并在该字段下设置了一个iOS UITextFlied secureTextEntry在iOS 6.1上不工作,ios,objective-c,uibutton,uitextfield,ios6.1,Ios,Objective C,Uibutton,Uitextfield,Ios6.1,我已经设置了一个密码字段,并在该字段下设置了一个ui按钮,以将securetextcentry切换为YES/NO 下面是我使用的代码 - (void)viewDidLoad { self.navigationController.navigationBarHidden=YES; [_ShowPasswordButtonOutlet setImage:[UIImage imageNamed:@"box.png"] forState:UIControlStateNormal];
ui按钮
,以将securetextcentry
切换为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;
}
}
上述代码似乎在iOS7和iOS7.1中运行
但是在iOS6.1中,单击按钮时按钮图像似乎在改变,但从YES
到NO
时,secureTextEntry
只工作一次。稍后,如果仅单击ui按钮
,图像将更改,并且secureTextEntry
将不工作
它没有显示任何警告或错误 在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;
}
}
您正在比较
iUI图像
?不要这样做,使用布尔标志或只需检查密码。secureTextEntry。也可以考虑使用UISwitc'而不是<代码> UIButton < /代码>,它有一个状态。同样按照惯例,方法和变量名以小写字母开头。谢谢你提供的信息。不要比较图像,而使用布尔值。好的。禁用UITextField
有效。我只是想知道为什么这只是在iOS6.1及以下版本中的一个问题,因为它在iOS7.0及以上版本中运行良好。@Zaph你是对的,因为答案不是直接关于这一部分的,所以我没有注意它。现在编辑,谢谢。