我想设置条件操作segue,这意味着当用户输入用户名和密码并单击登录按钮时,他将看到另一个屏幕,否则它将显示包含错误消息的UIAlertView。
这是我的登录方法的代码,它工作正常,它检查用户名和密码,如果匹配,它显示“成功”,否则它在输出中显示“错误”:
-(IBAction)login { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.example.com/db.php?username=%@&pass=%@",email.text,password.text]]; NSString *response = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; NSLog(@"response %@",response); }
我想要的是什么:
答案 0 :(得分:0)
您可以在用户点击登录按钮
时验证条目 -(IBAction)login {
if(email.text.length > 0 && password.text.length > 0) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.example.com/db.php?username=%@&pass=%@",email.text,password.text]];
NSString *response = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
if ([response isEqualToString:@"success"]) {
[self.navigationController pushViewController:vc1 animated:YES];
} else {
[self.navigationController pushViewController:vc2 animated:YES];
}
} else {
// show error alert message
}
}
答案 1 :(得分:0)
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
称之为
[self performSegueWithIdentifier:@"goToEditController" sender:self];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (<#condition#>) {
<#statements-if-true#>
} else {
<#statements-if-false#>
}
}