像 UiTableView 一样加载 UIScrollView

发布于 2025-01-03 23:54:23 字数 920 浏览 3 评论 0原文

有没有一种方法可以以与加载 UITableView 类似的方式加载 UIScrollView - 换句话说,仅加载可见的“单元格”?

对于我的示例,我有一个大滚动视图,可以向任何方向滚动。其中有“单元格”,我使用代码将其添加到滚动视图中。这些单元格由从 json feed 收集的数据组成(每个单元格一个 feed)。我只想加载可见单元格的提要,然后缓存已加载的提要,因此不需要重新加载它们。

有这样做的好方法吗?或者我应该采取另一个方向才能得到这个结果?

有几个答案建议采用平铺方法,但我不确定平铺是否是正确的方法,因为当部分单元可见时需要加载整个单元。谷歌暗示的另一种方法是将 UITableView 放入 UIScrollView 中,但我还没有尝试过。

         ——————————----------------------
         |        |                     |  < a 'cell' row in the scrollview
         | - - - -| - - - - - - - - - - |
screen > |        |                     |
         |        |                     |
         ——————————                     |
         |                              |  < whole of scrollable area
         |                              |
         |                              |
         |                              |
         --------------------------------

Is there a way to load a UIScrollView in a similar way to how a UITableView is loaded - in other words, only load the visible 'cells'?

For my example I have a large scroll view which can be scrolled in any direction. Inside that are 'cells' which I add to the scroll view using code. The cells consist of data gathered from json feeds (one feed per cell). I would like to only load the feeds for the visible cells, and then cache the ones already loaded, so they don't need to be reloaded.

Is there a good method of doing this? Or is there another direction I should be taking to get this result?

A couple of answers have suggested a tiling approach, but I'm not sure that tiling is quite the right approach, since the whole cell needs to be loaded when part of it is visible. Another approach which google hints at is putting a UITableView within a UIScrollView, but I've yet to try this.

         ——————————----------------------
         |        |                     |  < a 'cell' row in the scrollview
         | - - - -| - - - - - - - - - - |
screen > |        |                     |
         |        |                     |
         ——————————                     |
         |                              |  < whole of scrollable area
         |                              |
         |                              |
         |                              |
         --------------------------------

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文