ios - 移动行时如何防止UITableView滚动
<p><p>我正在开发一个必须支持 000 条记录的 UITableView 实现。我一直在使用 UITable InsertRows、DeleteRows 和 MoveRows 来根据需要随机播放记录。
在性能方面,这一切都在仅使用插入/删除时运行良好。
我发现 MoveRows 具有滚动表格以尝试将任何移动的行保留在表格的可见区域中的不良副作用。
当您有数千条记录时,这可能会导致表扫描,因此需要加载大量单元格。</p>
<p>我尝试了各种技术,例如禁用滚动,以试图防止内容偏移的变化 - 收效甚微。</p>
<p>一种解决方法是放弃 MoveRow,并将其替换为 InsertRow/DeleteRow 对。这确实有效,但代价是动画脱节,更重要的是,会丢失行选择。</p>
<p>任何人都可以在这里推荐一种已知可以达到预期效果的技术吗?</p>
<p>==== 更新====</p>
<p>我提到了“小成功”。如果 <code>ContentOffset</code> 是 <code>{0,0}</code>,我确实取得的成功是观察到表未尝试 <code>ContentOffset</code> 重新定位。
所以,我的 hack 是移动到没有动画的 <code>ContentOffset = {0,0}</code>,批量更新,然后恢复 <code>ContentOffset</code>。该表似乎在实际 <code>MoveRow</code> 调用内部的某个位置预先计算了它是否会重新定位。所以 - 我可以快速将偏移量移动到零并再次返回,而用户不会看到它。然后表格开始动画。</p>
<p>例如</p>
<pre><code>var contentOffset = _table.ContentOffset;
_table.PerformBatchUpdates(() =>
{
_table.MovRows(...);
});
_table.SetContentOffset(contentOffset, false);
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 Objective c 中你可以做到这一点...</p>
<pre><code>dispatch_async(dispatch_get_main_queue(), ^{
[UIView performWithoutAnimation:^{
//Your operation on tableview goes here...
});
</code></pre>
<p>你可以这样做</p>
<pre><code> DispatchQueue.async(DispatchQueue.main.async {
UIView.performWithoutAnimation {
//Your tableview operation goes here
}
})
</code></pre></p>
<p style="font-size: 20px;">关于ios - 移动行时如何防止UITableView滚动,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48538155/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48538155/
</a>
</p>
页:
[1]