I'm new to iOS and I'm trying to make a user registration app. Code:
-(void) registerNewUser{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:_usernameField.text forKey:@"username"];
[defaults setObject:_passwordField.text forKey:@"password"];
[defaults setBool:YES forKey:@"registered"];
[defaults synchronize];
UIAlertController *success = [UIAlertController alertControllerWithTitle:@"Success"
message:@"You are registered"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK Action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
NSLog(@"OK Action");
}];
[success addAction:okAction];
[self presentViewController:success animated:YES completion:nil];
[self performSegueWithIdentifier:@"login" sender:nil];
}
The issue I'm encountering is
Warning: Attempt to present <WelcomePageViewController: 0x7fa1d3cecbb0> on <RegistrationViewController: 0x7fa1d3c49d70> which is already presenting <UIAlertController: 0x7fa1d3c5fd40>
where WelcomePageViewController
is the next view controller I want to go to. I have searched through this, this and this.
Well from the fist link's accepted answer I came to know that if you have told a view controller to presentViewController:..., you cannot do that again until the presented view controller has been dismissed.
In my case during simulation I get the success you are registered
message i.e up untill [self presentViewController:success animated:YES completion:nil];
but the next line [self performSegueWithIdentifier:@"login" sender:nil];
do not execute i.e the program is not segueing to next view controller since the present controller is busy with the alert controller.
When I comment out [self presentViewController:success animated:YES completion:nil];
I do go to the next view controller. But I want to get the alert message and then segue to the next view controller. How would that be possible?