我是IOS的新手。我正在 IOS 中使用一个登录按钮制作登录 View Controller 。我有两个可能的 view-controllers
当用户单击登录按钮时可能会显示。我正在使用 Storyboard
但我只能将一个 segue 分配给一个按钮。我不知道如何执行该条件,因为我似乎无法 100% 控制 segue。
这是我的代码:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *stringreponse=[[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
// NSLog(@"Split response %@", [splitresponse objectAtIndex:0]);
if([stringreponse isEqualToString:@"0"])
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Wrong username or password" message:@"Wrong username or password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
else
{
NSArray *splitresponse=[stringreponse componentsSeparatedByString:@"#"];
if([[splitresponse objectAtIndex:0] isEqualToString:@"Parent"])
{
if([[splitresponse objectAtIndex:2] isEqualToString:@"yes"])
{
//seguechoice=@"showParentRegistration";
//[self performSegueWithIdentifier:@"showParentRegistration" sender:self ];
}else{
//seguechoice=@"showSohoDashboard";
}
}
}
}
最佳答案
您可以将一个 segue 分配给一个 UI 控件,但您可以将多个 segue 分配给一个 viewController。只需将它们全部添加到 viewController,给每个不同的 id,然后调用这些 id
if([[splitresponse objectAtIndex:2] isEqualToString:@"yes"])
{
[self performSegueWithIdentifier:@"showParentRegistration" sender:self ];
}
else
{
[self performSegueWithIdentifier:@"showSohoDashboard" sender:self ];
}
关于ios - 根据条件导航到不同 View Controller 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21157863/