如何让这两个NSSecureTextField持续检查它们是否相等/不同以显示图像而不需要按钮?
.h文件:
IBOutlet NSSecureTextField *textField;
IBOutlet NSSecureTextField *textField2;
IBOutlet NSImageView *imagem;
}
- (IBAction)verificarPass:(id)sender;
.m文件:
- (IBAction)verificarPass:(id)sender;
{
NSString *senha1 = [textField stringValue];
NSString *senha2 = [textField2 stringValue];
NSImage *certo;
NSImage *errado;
certo = [NSImage imageNamed:@"Status_Accepted.png"];
errado = [NSImage imageNamed:@"Error.png"];
if ([senha1 isEqualToString:senha2]) {
[imagem setImage:certo];
}else{
[imagem setImage:errado];
}
}
答案 0 :(得分:0)
将目标方法添加到textField控件,由UIControlEventEditingChanged
控件事件触发:
[textField addTarget:self action:@selector(verificarPass:) forControlEvents:UIControlEventEditingChanged];