2014-09-13 60 views
-1

我知道这不是最安全的方式,但它只是一个初学者应用程序,所以我使用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 

再次感谢!

+3

你有没有在passwordField.text中调试什么? – tttthomasssss 2014-09-13 16:43:18

+2

您是否将iVar passwordField链接到xib? – seanxiaoxiao 2014-09-13 16:44:22

回答

2

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

+0

如何链接界面构建器中的passwordField? – 2014-09-13 20:25:04

+0

@DawsonSeibold https://developer.apple.com/library/ios/recipes/xcode_help-interface_builder/articles-connections_bindings/CreatingOutlet.html – 2014-09-14 03:13:48

+0

好的谢谢你的所有帮助 – 2014-09-16 16:05:20