Xcode Objective-C Segue Presentation In Progress

I am trying to develop an application in which it allows users to login with AFNetworking. I have a database configured correctly, and everything seems to be working fine, except when the user first logs in.

I have a very simplified one:

[[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 user login data, only successfully if the login data matches. As you can see above, I clearly set the user to sharedInstance, which is used throughout the application. After the user is configured, I try to execute segue as the login button does.

Seg happens and the program works, but there are 2 problems that I can’t solve, and I spent hours trying to fix it. First, I get a message in the Xcode output window:

A warning. Try submitting a UITabBarController to LoginVC while the presentation continues!

And secondly, to check the correct installation of the user, on the "Profile" screen (on the first screen) there is a label on which the text is installed:

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

And this will hit or skip if the username appears or says (null), as shown:

enter image description here

You can also see the button I made there to print user values ​​in the output window. Even when the message is "Welcome (null)" and I click the button, all the values ​​are correct there, so I'm not sure why the string sometimes indicates null.

Here is the storyboard setting regarding the issue I am having:

enter image description here

If anyone could help me with this, I would really appreciate it.

+7
source share
2 answers

As you correctly diagnosed, the problem is certainly some strange and / or duplicate call to segues. If you look at your project, the problem is that your β€œLogin” button has both an IBAction method and segue from this login screen to the following controller (tab bar controller):

both IBAction and segue

This is a problem because segue will start when you press the button, but will be called again by your code - (IBAction)login:(id)sender .

Since you have IBAction , the segue should not be from the button to the next controller, but rather from the controller itself. Thus, delete the 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 this new Login ID, and now your Login button will not automatically execute the session itself, but will allow IBAction to do its work and manually performSegueWithIdentifier as necessary.

+9
source

Send / fire event: Did End On Exit

Connect it to your method calling performSegueWithIdentifier .

Thus, it will not start twice.

0
source

All Articles