一个按钮,根据条件导航到不同的视图控制器

问题描述 投票:1回答:2

我是IOS的新手。我正在IOS中创建一个登录视图控制器,其中有一个按钮即可登录。我有两个可能的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";
            }
        }
    }
}
ios iphone objective-c segue xcode-storyboard
2个回答
3
投票

您可以将一个segue分配给一个UI控件,但可以将多个分配给一个viewContoller。只需将它们全部添加到viewController,给每个id不同的id,然后调用那些id

if([[splitresponse objectAtIndex:2] isEqualToString:@"yes"])
{
    [self performSegueWithIdentifier:@"showParentRegistration" sender:self ];
}
else
{
    [self performSegueWithIdentifier:@"showSohoDashboard" sender:self ];
}

0
投票

在故事板中创建从源视图控制器到目标视图控制器(不是按钮)的2个连接。插入两个不同的标识符,当按下按钮时,执行条件并运行segue取决于条件:

if(CONDITION TO RUN SEGUE !)
{
   [self performSegueWithIdentifier:@"SEGUEIDENTIFIER1" sender:self ];
}else {
    [self performSegueWithIdentifier:@"SEGUEIDENTIFIER2" sender:self ];
}
© www.soinside.com 2019 - 2024. All rights reserved.