[英]How can I get a button to determine which viewcontroller to go to?
I'm trying to use Xcode to take the value of a usertype input and do one of three things: if the usertype is invalid it will stay on the current view controller and tell the user the credentials are invalid, if it is valid and "admin" it will go to the user settings, and if it is "user" or null it will go to the order list. 我正在尝试使用Xcode来获取用户类型输入的值,并执行以下三项操作之一:如果用户类型无效,它将停留在当前视图控制器上,并告诉用户凭据无效,如果有效,则“ admin”将转到用户设置,如果为“ user”或为null,则将转到订单列表。
I already have the if statements built, just not sure how to specify what view controller to go to. 我已经建立了if语句,只是不确定如何指定要转到的视图控制器。
I didn't really understand your question, but can't you simply allocate the view like this: 我不太了解您的问题,但是您不能简单地分配这样的视图:
if(!error) {
ViewController *viewcont = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self presentViewController:viewcont animated:NO completion:nil];
} else {
ViewController2 *viewcont2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
[self presentViewController:viewcont2 animated:NO completion:nil];
}
If you are using navigation controller 如果您使用的是导航控制器
if(!error) {
ViewController *view1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:view1 animated:YES];
} else {
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
[self.navigationController pushViewController:view2 animated:YES];
}
Otherwise use this 否则使用这个
if(!error) {
ViewController *view1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self presentViewController:view1 animated:NO completion:nil];
} else {
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
[self presentViewController:view2 animated:NO completion:nil];
}
Remember: this solution will not work if your views are not xnib
files, I mean if you are using storyboard 请记住:如果您的视图不是
xnib
文件,则此解决方案将不起作用,我的意思是如果您使用情节xnib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.