Я знаю, что это не самый безопасный способ, но это просто приложение для начинающих. Поэтому я использую 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
Вы связали iVar passwordField с xib? – seanxiaoxiao