Domanda

I have a Login page with a button. When I click on it, IF and ONLY IF the login was successful, I want to pass data to another class (using properties).

I have tried using a Segue on the Button to pass the data, but the problem is that this Segue always goes to the next View, EVEN when the login is unsuccessful, in which case it should NOT.

 -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {            
if ([[segue identifier] isEqualToString:@"gotoMainPage"] ) {
MainPageController *mpc = [segue destinationViewController];     
mpc.username = @"TEST";    }

How can I make the Segue ONLY go to the destinationController, if the login is successful ?

I am aware that there are other ways to go to another ViewController, such as setting an IBAction on the button, and when login is successful, use instantiateViewControllerWithIdentifier and presentViewController, and I HAVE tried with those too, but the issue here is that, it does NOT pass the data to another class.

Help is appreciated. Thanks

È stato utile?

Soluzione

You connect the segue from the controller (not a button), and then after your condition is met, call performSegueWithIdentifier in code.

Altri suggerimenti

Once prepareForSegue:sender: has been called, you can't stop the segue from happening.

You should check for the criteria and call the performSegueWithIdentifier method conditionally.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top