Search code examples
iosiphoneobjective-cseguexcode-storyboard

A button which navigates to different view controllers depending on the condition


I am new to IOS. I am making a login view controller in IOS with one button which is sign in. I have two possible view-controllers that might be shown when the user click on the sign-in button. I am using Storyboard but I can only assign one segue to one button. I don't know how to perform the condition since I seem not to have 100% control over the segue. Here is my code:

- (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";
            }
        }
    }
}

Solution

  • you can assign one segue to one UI control but you can assign many to a viewContoller. Simply add all of them to the viewController, give each a different id and then call those id's

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