문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top