菜鸟教程小白 发表于 2022-12-11 19:17:14

ios - UITableViewCells 内部带有 UICollectionView 低性能(Swift)


                                            <p><p>我有一个 tableview,每个单元格中都嵌套了一个 collectionView。</p>

<p>tableViewCell 的数量是动态的,每个 tableViewCell 的 collectionViewCell 的数量也是动态的。</p>

<p>我“dequeueReusableCell”这两种单元格。</p>

<p>每次加载 tableViewCell 时,我都会执行 cell.collectionView.reloadData()。 </p>

<p>当我滚动 TableView 时,它真的在抽搐。加上 viewController 需要大量加载。</p>

<p>我尝试将collectionView.reloadData() 移到uitableviewcell 的prepareforReuse 或willDisplayCell 中,但没有。</p>

<p>我发现很少有帖子问这个问题,但实际上我无法解决我的问题。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>使用 <code>reloadData()</code> 方法就像使用锤子一样。这要花很多钱,因为您说要重新加载所有数据。 </p>

<p>要问自己的问题是:“我需要每次都重新加载所有数据吗?还是只需要一部分?只需一行 <code>func reloadRows(at: , with: UITableViewRowAnimation)</code> ? 可能只是一个部分与 <code>func reloadSections(_sections: IndexSet, with animation: UITableViewRowAnimation)</code> ?</p>

<p>通过这些方法,您可以降低成本并稍微加快程序速度。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UITableViewCells 内部带有 UICollectionView 低性能(Swift),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47269659/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47269659/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UITableViewCells 内部带有 UICollectionView 低性能(Swift)