我编写了一个简单的应用程序来验证用户输入(无论是 NULL 还是超过定义的长度)。当验证失败时,它应该返回验证错误消息,否则,重定向到另一个页面。
但是,该应用程序仅返回所有场景的第一个条件(用户名为空)的消息。(如用户名填写,密码为空等)
.m 文件:
- (IBAction)doLogin {
if(uname.text==NULL) {
UIAlertView *err1 = [[UIAlertView alloc]
initWithTitle:@"Required field!" message:@"Username is empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[err1 show];
NSLog(@"%@",uname.text);
}
else if(passw.text==NULL) {
UIAlertView *err2 = [[UIAlertView alloc]
initWithTitle:@"Required field!" message:@"Password is empty." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[err2 show];
NSLog(@"%@",passw.text);
}
else if (uname.text.length < 6)
{
UIAlertView *err3 = [[UIAlertView alloc]
initWithTitle:@"Invalid!" message:@"Enter a username longer than 6 chars." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[err3 show];
NSLog(@"%@",uname.text);
}
else if (uname.text.length < 8)
{
UIAlertView *err4 = [[UIAlertView alloc]
initWithTitle:@"Invalid!" message:@"Enter a password longer than 8 chars." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[err4 show];
NSLog(@"%@",uname.text);
}
else {
/*UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Thank you" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"OK", nil];
[alert show];*/
UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:@"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];
}