My app has a tab bar controller, one of the tab items is a split view controller. It's master view controller (ie. at index 0) is a navigation controller loaded from a nib, due to it's custom navbar.
If that sounds a bit obscure, well it's down to a combination of 1) not being able to add an SVC to a TBC in IB and 2) the iOS 4.2 splitview-navbar-colorTint bug. And indeed, it's only since implementing the workaround yesterday that I've been experiencing a problem with low memory warnings.
Before the workaround I was initting the SVC with 2 nav controllers and adding it to the TBC all programatically (due to IB's restricions with th tab bar) and without and problems - well, except for that apple bug.
The little workaround demo also works fine, even after low memory warnings. But it doesn't involve the additional overhead of a tab bar.
But in my adaption of the workaround demo it starts to all go pear shaped. Send a low memory warning whilst showing the split view and the whole left side (master view) disappears. Behaviour identical on device, in fact I first discovered it there.
I'm puzzled what's going on. The view on display (the nav cont's root view) is controlled by a table view subclass. I've overridden didReceiveMemoryWarning but that doesn't help. Furthermore (correspondingly!), the superview isn't nil. It's a UITableView. Perfectly correct.
So, I'm thinking the nav controller is getting released? But where? And why not in the original demo? The difference now is the addition of my tab bar controller. Here's my code that adds it to the tab bar:
- (void) addTabItemSplitViewWithNavConRoot:(BOOL)hasRootNC {
// init master/detail views
SV1RootViewController *rvc = [[SV1RootViewController alloc] initWithNibName:@"SVC1RootView" bundle:nil];
SV1DetailViewController *dvc = [[SV1DetailViewController alloc] initWithNibName:@"SVC1DetailView" bundle:nil];
rvc.detailViewController = dvc;
UINavigationController *nc = nil;
if (hasRootNC) {
nc = [self.pSVC1.viewControllers objectAtIndex:0];
nc.viewControllers = [NSArray arrayWithObjects:rvc, nil];
nc.navigationBar.tintColor = [UIColor redColor];
} else {
nc = nil;
}
UIViewController *vc = (hasRootNC)? (UIViewController*)nc :rvc;
UISplitViewController *svc = [self newSplitViewControllerWithMasterVC:vc detailVC:dvc];
svc.delegate = dvc;
// init the tab bar item
svc.tabBarItem = [[UITabBarItem alloc] initWithTitle:(hasRootNC)? @"SplitView with Nav Root":@"Simple SplitView"
image:nil
tag:0];
// int the split view
NSMutableArray *controllersArray = [NSMutableArray arrayWithArray:self.pTabBarController.viewControllers];
[controllersArray addObject:svc];
[self.pTabBarController setViewControllers:controllersArray];
// cleanup
[nc release];
[rvc release];
[dvc release];
[svc release];
}
- (UISplitViewController*) newSplitViewControllerWithMasterVC:(UIViewController*)masterView
detailVC:(UIViewController*)detailView {
UISplitViewController *svc = [[UISplitViewController alloc] init];
NSMutableArray *controllersArray = [NSMutableArray arrayWithObjects:masterView, detailView, nil];
[svc setViewControllers:controllersArray];
return svc;
}
Anybody have ideas for me please? :)
It's driving me insane!!!