Search code examples
iphoneiosxcodeuitabbarcontrolleruitabbar

When going back from Flip Side of Tab Bar, Tab Bar Doesn't Load. iOS


So I have a tab bar app with three tabs. In the second tab, I have a button that loads another view in which two text fields pass their values into two labels in the original tab view. When I click the button, enter my values, and click the set button to go back to the original view, the labels are changed, but the tab bar doesn't load. How do I load the tab bar after switching from a different view?

Code for when the button in the original tab bar view is pressed

TeamNameViewController *fvc = [self.storyboard instantiateViewControllerWithIdentifier:@"99"];

fvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:fvc animated:YES completion:nil];

Code to go back to tab bar

 SecondViewController *tempView = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewControllerSB"];

tempView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:tempView animated:YES completion:nil];

Solution

  • The short answer is: You don't.

    presentViewCntroller:animated:completion presents the target view controller modally. The other views still exist and you don't need to instantiate them again, you need to dismiss the modal view controller.

    You need to call dismissViewController:animated:completion on the presenting view controller (that is the view controller that calls presentViewController:animated:completion is responsible).