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

+2

Вы связали iVar passwordField с xib? – seanxiaoxiao

ответ

2

Возможно, вы не связали свой парольField в построителе интерфейса.

+0

как вы связываете passwordField в построителе интерфейса? –

+0

@DawsonSeibold https://developer.apple.com/library/ios/recipes/xcode_help-interface_builder/articles-connections_bindings/CreatingOutlet.html –

+0

ОК спасибо за помощь –

Смежные вопросы