我知道这不是最安全的方式,但它只是一个初学者应用程序,所以我使用ifEqualToString
,它只是去else语句。请帮忙。我甚至复制并粘贴了密码,但仍然不正确。IsEqualToString每次都失败
这里是我的 ViewController.H
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)enterPassword:(id)sender {
NSLog(@"testOne");
NSString *passwordString = [NSString stringWithFormat:@"1234"];
if ([passwordField.text isEqualToString: passwordString]) {
// Password is correct
NSLog(@"Password Correct");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Password" message:@"This password is correct." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
else {
// Password is incorrect
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incorrect Password" message:@"This password is incorrect." delegate:self cancelButtonTitle:@"try Again" otherButtonTitles:nil];
[alert show];
NSLog(@"password Incorrect");
}
}
@end
再次感谢!
你有没有在passwordField.text中调试什么? – tttthomasssss 2014-09-13 16:43:18
您是否将iVar passwordField链接到xib? – seanxiaoxiao 2014-09-13 16:44:22