导航控制器太多?

发布于 2024-12-07 02:47:57 字数 297 浏览 0 评论 0原文

我认为我的项目做了一些可笑的错误。我正在制作一个项目,基本上是一组视图控制器,其中一些控制器上有视频,其他控制器上有图像。我创建了一个模型,但我认为我过多地推动导航控制器做它不应该用于的事情。

这就是我所做的:我创建了四个视图控制器和一个导航控制器。第三个视图控制器有一个 MPMoviePlayer 作为子视图。我从其超级视图控制器的任何转换中将其从视图中删除,但是我想到,如果我有一百个这样的视图控制器,那么位于其中的第 100 个意味着有 99 个视图被卸载。这不是一个真正的病态问题还是我无缘无故地吓坏了?因为我真的不知道如何以其他方式做到这一点。 谢谢。

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. The 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌化 2024-12-14 02:47:57

您是否严格单向移动,即只推送视图控制器而不弹出它们?这是非常糟糕的做法,尽管通过适当的内存管理,您可以在应用程序崩溃之前在堆栈中获得大量的 VC。

如果您以非来回堆栈的方式在四个 VC 之间跳转(例如导航控制器)或使用像选项卡栏这样的全局控件,那么您最好从其超级视图中删除前一个视图并将其替换为新视图。例如,在您的应用程序委托中:

-(void)switchToView:(UIViewController*)newVC
{
    if (self.currentVC!=nil)
        [self.currentVC.view removeFromSuperview];
    self.currentVC = newVC;
    [self.window addSubview:newVC.view];
}

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];
}
亽野灬性zι浪 2024-12-14 02:47:57

UIViewController 将在需要时卸载其视图。如果您的深度为 100 级,那么您将只有少数视图仍在加载。这就是为什么实现 viewDidUnload 并将您的 IBOutlet 设置为 nil 非常重要。

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 IBOutlets to nil.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文