Question

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";
            }
        }
    }
}
Était-ce utile?

La 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 ];
}

Autres conseils

Create 2 connection in storyboard from your source view controller to destination view controller (not button). Insert two different identifiers and when the button is pressed do condition and run a segue depends on the condition:

if(CONDITION TO RUN SEGUE !)
{
   [self performSegueWithIdentifier:@"SEGUEIDENTIFIER1" sender:self ];
}else {
    [self performSegueWithIdentifier:@"SEGUEIDENTIFIER2" sender:self ];
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top