I currently have 3 ViewControllers: LoginViewController, SignUpViewController and MainViewController.
When the user opens the app, LoginViewController will be presented. If its the user's first time using the app then they will have to sign up, the "Sign Up" button is in the LoginViewController. The "Sign Up" button will bring up the SignUpViewController.
Once the user finished signing up. The MainViewController will be presented.
What I am trying to do is. In the MainViewController there will be a "Log Out" button. When the user press it the MainViewController should be dismissed and LoginViewController should be there. The user should not see the SignUpViewController for the second time.
Here is what I have tried:
1) Dismiss SignUpViewController and present MainViewController in "sign up" button:
- (void) signUpClicked
{
MainViewController *mainViewController = [viewController.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[viewController presentViewController:mainViewController animated:YES completion:^{
[viewController dismissViewControllerAnimated:NO completion:^{
}];
}];
}
2) When MainViewController loads, dismiss SignUpViewController
- (void)viewDidLoad
{
[super viewDidLoad];
SignUpViewController *signUpViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SignUpViewController"];
[signUpViewController dismissViewControllerAnimated:NO completion:^{
}];
}
Got it. I passed the SignUpViewController to the MainViewController and dismiss the SignUpViewController in the MainViewController.
For anyone else who had the same question as me.
SignUpViewController.m
- (void) signUpButtonClicked
{
MainViewController *mainViewController = [viewController.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
mainViewController.signUpViewController = viewController;
[viewController presentViewController:mainViewController animated:YES completion:^{
}];
}
MainViewController.m
- (IBAction)logoutClicked:(id)sender
{
[self dismissViewControllerAnimated:YES completion:^{
[self.signUpViewController dismissViewControllerAnimated:NO completion:^{
}];
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With