ios - UITableView 中可见单元格的数量

标签 ios uitableview

我有一个 UITableView,它比它的父 View 稍小。每个单元格的高度与表格的高度相同(一次只有一个单元格完全可见)。

UITableViewclipsToBounds 设置为 NO 以便能够看到下一个单元格的顶部。

但下一个单元格未加载到 visibleCells 中,因为它不适合 UITableView。当我开始滚动时,它会出现(或者如果我将单元格高度设置为少 1 个像素)。如何让 UITableView 始终加载 2 个单元格,而不是只加载适合表格的单元格?

views hierarchy

在此图中,第二个 UITableViewCell 默认情况下不加载,仅在我开始滚动时加载。

PS:我还在 TableView 上使用了 pagingEnabled

最佳答案

您可以使 tableview 大于单个单元格,然后设置 tableview 内容插入,以便顶部和底部单元格在最大/最小滚动时出现在正确的位置。您还可以在不应该存在的 tableview 部分(当前不存在的较大部分)上放置一个不可见 View ,这样 tableview 的这一部分仍然不可选择。

这可能需要一些工作,但确保绘制单元格的唯一方法是将其显示在屏幕上。

在进一步研究中,this guy说同样的话,但出于不同的原因。

2. UITableView buffering

This may be one of the simplest changes you can make to improve perceived performance in any iOS application. Simply enough, if you want to preload data of you table view beyond the visible bounds of the table view, you need only extend the table view itself to achieve the desired buffer. For example, you have an iPhone app that has a full screen table view (320x480 or 320x568). If you want the table view to buffer an extra table view height of data, you just make your table view twice as tall (320x960 or 320x1136) and then counter the height extension using UIScrollView's contentInset and scrollIndicatorInsets properties. It really is that easy. With this simple change to your table views, you now have the ability to avoid showing table view cells with blank content as the content is downloaded and then have the content jarringly show up.

关于ios - UITableView 中可见单元格的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21053874/

相关文章:

ios - 使用 dequeueReusableCell 重写单元格

ios - 如何以编程方式在自定义表格 View 中附加搜索栏

ios - fetchLimit 返回第一项而不是最后一项

ios - 为什么对象的可变性与其线程安全相关?

ios - 使用现有字符串作为 valueForKey 值

ios - 插入带有动画的 UITableViewCell 并滚动到它

ios - Apple Watch 在 15 分钟后失去与 iOS 应用程序的连接

ios - 如何在不调用的情况下从另一个应用程序中打开电话应用程序?

ios - 如何根据单元格内容更改单元格高度?

ios - UICollectionView 仅防止第一个单元格重复使用单元格