Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Objective-C Segue "Presentation in Progress"

I'm trying to develop an application where it allows user logins with AFNetworking. I have the database set up correctly and everything seems to be working fine except when the user first logs on.

What I have is very simplistic:

[[API sharedInstance] commandWithParams:params
                               onCompletion:^(NSDictionary *json) {
                                   //result returned

                                   NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];

                                   if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"UserID"] intValue]>0) {
                                       [[API sharedInstance] setUser: res];
                                       [self performSegueWithIdentifier:@"Login" sender:self];
                                   } else {
                                       //error
                                       [UIAlertView title:@"Error" withMessage:[json objectForKey:@"error"]];
                                   }

                               }];

Basically, the above code returns the result for a user login details, successful only if login details match. As you can see above, I clearly set the user in the sharedInstance, used throughout the application. After the user is set I attempt to perform the segue, as that's what a login button should do.

The segue does occur and the program is operational, but there's 2 issues I can't work out and I've been spending hours trying to fix it. First I get the message in Xcode's output window:

Warning: Attempt to present UITabBarController on LoginVC while a presentation is in progress!

And secondly, to test that the user was set correct, on the Profile screen (the first screen segued to) have a label that has it's text set to:

NSString stringWithFormat:@"Welcome %@",[[[API sharedInstance] user] objectForKey:@"username"]];

And it's a hit or miss whether the username actually appears or says (null) as shown:

enter image description here

You can also see a button I made there, to print to the output window the values of user. Even when the message is "Welcome (null)" and I press the button, all the values are correctly there so I'm unsure why the string sometimes states null.

Here's the storyboard setup regarding the issue I'm having:

enter image description here

If anyone could help me on this one I would truly appreciate it.

like image 555
John Bale Avatar asked Nov 06 '12 18:11

John Bale


1 Answers

As you correctly diagnosed, the problem is definitely some strange and/or duplicative invocation of the segues. Looking at your project, the problem is that your "Login" button has both an IBAction method as well as a segue from that login screen to the next controller (the tab bar controller):

both IBAction and segue

That's a problem, because the segue will be triggered when you hit the button, but will be triggered again by your - (IBAction)login:(id)sender code.

Because you have an IBAction, the segue should not be from the button to the next controller, but rather from the controller itself. Thus, delete your existing Login segue from the button to the next screen and recreate it from the controller itself:

create segue from controller to next scene

Give that new segue the "Login" identifier, and now your "Login" button will not automatically perform the segue itself, but will let the IBAction do its work and manually performSegueWithIdentifier as appropriate.

like image 183
Rob Avatar answered Nov 10 '22 09:11

Rob