2014-09-13 91 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