Too many navigation controllers?
I think I'm doing something ridiculously wrong with my project. I'm making a project that basically is a set of view controllers with videos on some of them, images on the others. I created a mockup, but I think I'm pushing Navigation Controller too much doing what it's not supposed to be used for.
Here is what I did: I created four view controllers and a navigation controller. T开发者_高级运维he third view controller has a MPMoviePlayer as a subview. I remove it from the view on any transition from its super view controller, however it came to me that, if I'll have a hundred of these view controllers, being on the 100th of them means having 99 views unloaded. Isn't that a really sick problem or I'm freaking out without any reason? Because I don't really know how to do it the other way. Thank you.
Are you moving strictly one-way, ie, only ever pushing view controllers and never popping them? This is pretty bad practice, although with proper memory management you could get a very large number of VCs in the stack before your app crashes.
If you're jumping around between four VCs in a way that's not a back-and-forth stack (like a navigation controller) or using a global control like a Tab Bar, you're probably better off removing the previous view from its superview and replacing it with the new view. For example, in your app delegate:
-(void)switchToView:(UIViewController*)newVC
{
if (self.currentVC!=nil)
[self.currentVC.view removeFromSuperview];
self.currentVC = newVC;
[self.window addSubview:newVC.view];
}
A UIViewController will unload it's view when it needs to. If you were 100 levels deep you would only have a few views still loaded. That is why it is important to implement viewDidUnload
and set your IBOutlet
s to nil
.
精彩评论