OGeek|极客世界-中国程序员成长平台

标题: ios - 避免在自定义 UIViewController 容器中加载数百个 View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 03:56
标题: ios - 避免在自定义 UIViewController 容器中加载数百个 View Controller

我编写了一个自定义 UIViewController 容器,其行为类似于 Flipboard 的页面。用户可以滑动/点击作为 subview Controller 的“页面”。我觉得我写得很好,但我担心我会遇到可能有数百个 subview Controller 的场景。我想避免将所有这些 View Controller 加载到内存中(因为它们都将具有包含大量数据的 UICollectionViews)。

由于存在用于滑动 View 的手势交互,因此我需要将每个“下一个”和“上一个” View 添加到容器 View 并加载,以便在用户开始在另一个页面上滑动时可见。

如何阻止每个 View Controller 的 -viewDidLoad 发生,以便仅在需要时加载每个 View Controller ?是否有任何“最佳实践”或示例 UIViewController 容器在那里我可以得到一些关于仅加载下一个/上一个子 Controller 的想法?



Best Answer-推荐答案


理论上你应该有一个容器 UIViewController 和两个 UIViewControllers (就像你说的那样)。一个将是下一个,另一个将是前一个。然后,您可以保留对两者的引用,当您即将转到下一个(例如)时,您只需更新它,例如:

- (void)updateViewControllerUIViewController *)viewController withDataSourceNSDictionary *)dataSource;

最后你有 3 个 UIViewControllers。其他解决方案也是可能的,您可以随时查看 GitHub 或 CocoaControls 以获得一些灵感。

关于ios - 避免在自定义 UIViewController 容器中加载数百个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15909501/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4