title: Unbalanced calls to begin/end appearance transitions for...- UIViewController containment
body: <p><img src="https://i.stack.imgur.com/cOiqM.jpg" alt="enter image description here"></p>
  
  <p>Ok, so with iOS 5 Apple introduced view controller containers (awesome!)</p>
  
  <p>Above is what the layer of my app looks like. TabBar contains NavController contains ViewController (container) which holds 2 table views, toggled by a segmented control.</p>
  
  <p>When I pick a table cell, it pushes the new view easily. However, if I press a button within the detailViewController, i want it to modally show MFMailComposeViewController. Which presents itself briefly, then instantly dismisses itself. The error log I get is:</p>
  
  <blockquote>
    <p>Unbalanced calls to begin/end appearance transitions for UITabBarController</p>
  </blockquote>
  
  <p>Now, this means im trying to present a view while the other is still showing or in runtime loop, ive tried adding delays to stop this, but nothing works. Ive added all my delegates, and imported all my libraries correctly. </p>
  
  <p>I think it may have something to do with how i push new views from the original tableview or how I load views into the container. The project uses the base code for Xcode's Tab Bar app template, just so you know. Here's the code:</p>
  
  <p>ViewController / Container</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      // Alloc Init View Controllers
      menuDrinksViewController = [[MenuDrinksViewController alloc] init];
      menuFoodViewController = [[MenuFoodViewController alloc] init];
  
      // Create Parent/Child relationship
      [menuFoodViewController didMoveToParentViewController:self];
      [self addChildViewController:menuFoodViewController];
  
      [menuDrinksViewController didMoveToParentViewController:self];
      [self addChildViewController:menuDrinksViewController];
  
      [appearanceClass setBackgroundImage:self.view];
  
      // segmented controller
      segmentedControl = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"              Eat              ", @"               Drink               ", nil]];
      [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
      [appearanceClass setSegmentedControl:segmentedControl];
      [self.view addSubview:segmentedControl];
  
      //self.view.backgroundColor = [UIColor redColor];
  
      // Add and Size subviews
      [self.view addSubview:menuFoodViewController.view];
      menuFoodViewController.view.frame = CGRectMake(0, 39, 320, self.view.frame.size.height - 40 + 1);
      menuDrinksViewController.view.frame = CGRectMake(0, 39, 320, 327 + 1);
  }
  
  
  -(IBAction)segmentAction:(id)selector
  {
      // it's a custom segmented control, dw bout the code.
      if (segmentedControl.selectedIndex == 0)
      {
          [self.view addSubview:menuFoodViewController.view];
          [menuDrinksViewController.view removeFromSuperview];
      }
      else if (segmentedControl.selectedIndex == 1)
      {
          [self.view addSubview:menuDrinksViewController.view];
          [menuFoodViewController.view removeFromSuperview];
      }
  
  }
  </code></pre>
  
  <p>TableViewController</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      MenuFoodDetailViewController *menuFoodDetailViewController = [[MenuFoodDetailViewController alloc] initWithNibName:nil bundle:nil];
      //MenuFoodDetailViewController *menuFoodDetailViewController = [[MenuFoodDetailViewController alloc] init];
  
      [self.parentViewController.navigationController pushViewController:menuFoodDetailViewController animated:YES];
      [tableView deselectRowAtIndexPath:indexPath animated:NO];
  }
  </code></pre>
  
  <p>ButtonPress Code from detail view controller.</p>
  
  <pre><code>- (void)showMailComposer
  {
      // attempt to delay the presentModalView call, doesnt work...
      double delayInSeconds = 0.1;
      dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
      dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
          [self.navigationController presentModalViewController:mailComposeViewController animated:YES];
      });
  }
  </code></pre>
  
  <p>I know this is a lot to ask, but ive been at this for days.
  All code not associated with views, i.e. MFMailViewComposer works fine, I've tested it in other apps.</p>
  
  <p>I've tried all sorts of variations to push the new modal view, i.e.
  <code>self.parentViewController.navigationController presentModal...</code> (etc)</p>
  
  <p>Nothing is working =/</p>