我遇到了一个恼人的问题,我的UITextField
会返回错误的值。在名为“username”的UITextField中键入“test”应创建一个标题为“Good”的警报视图。但它显示我的错误警报视图。
有谁知道我做错了什么?
由于
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)buttonPress {
NSString *properUsername = @"test";
NSString *givenUsername = self.username.text;
if(givenUsername == properUsername){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Good"
message:nil
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wrong username/password combination"
message:nil
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
}
}
答案 0 :(得分:4)
使用isEqualToString
方法代替'=='
if ([givenUsername isEqualToString:properUsername])