So,
I started typically by init the controller from the nib and popping it onto the view stack. But the problem is that the first controller isn't really gone - its still around.
So, we started down the path of this:
Starting w/the appDelegate and loading the RootViewController:
mRootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
[(m42Window *)[application.windows objectAtIndex:0] setController:mRootController];
Going from RootViewController to RegionViewController:
RegionViewController *controller = [[RegionViewController alloc] initWithNibName:@"RegionViewController" bundle:nil];
[[self getWindow] setController:controller];
[controller release];
And the method:
- (void) setController:(m42ViewController *)controller
{
if (mController != nil)
{
for (UIView *view in mController.view.subviews)
{
if (view != nil)
{
[view removeFromSuperview];
}
}
[mController.view removeFromSuperview];
[mController release];
mController = nil;
}
mController = controller;
[mController retain];
[self insertSubview:mController.view atIndex:1];
}
Pictures of the issue here: RootViewController: http://mr-sk.com/img/rootViewController.png RegionViewController (Images visible from RootViewController): http://mr-sk.com/img/regionViewController.png
Now the issue is that images in the RootViewController are visible (I have an empty UIImageView that shows images on the controller below it) in the RegionViewController - for whatever reason the view isn't actually being removed from the super view and released. For many reason's we want these views gone:
- Memory foot print - why hold onto all kinds of assets we don't need. We can recreate them if the user navigates back
- Code - what if code is running in those other controllers. Well, we don't want that in this case. We want them gone.
So, what's wrong? Fundamentally, we've must have missed something in iphone 101 class. heh. I saw we cause this is myself and another guy.
Thanks.