gpt4 book ai didi

ios - 避免在自定义 UIViewController 容器中加载数百个 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:39 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

- (void)updateViewController:(UIViewController *)viewController withDataSource:(NSDictionary *)dataSource;

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com