IsEqualToString每次都失败

时间:2014-09-13 16:39:08

标签: objective-c

我知道这不是最安全的方式,但它只是一个入门应用程序,所以我使用ifEqualToString,它只是转到else语句。请帮忙。我甚至复制并粘贴了密码,但仍然标记错误。

这是我的 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
再次感谢!!

1 个答案:

答案 0 :(得分:2)

您可能没有在界面构建器中链接您的passwordField。

相关问题