Ok, so with iOS 5 Apple introduced view controller containers (awesome!)
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.
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:
Unbalanced calls to begin/end appearance transitions for UITabBarController
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.
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:
ViewController / Container
- (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];
}
}
TableViewController
- (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];
}
ButtonPress Code from detail view controller.
- (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];
});
}
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.
I've tried all sorts of variations to push the new modal view, i.e.
self.parentViewController.navigationController presentModal...
(etc)
Nothing is working =/