我的应用程序包括两个collectionViews,mainCollectionView和nestedCollectionView,它们都在mainCollectionViewCell中。
就像iPhone日历应用程序一样,mainCollectionView中的每个单元格都有代表一个月的nestedCollectionView (单元格的数量将是月份的天数)。
class cell_Main:UICollectionViewCell{
let collectionView:UICollectionView = {
let cv = nestedCollectionView()
cv.backgroundColor = .white
return cv
}()如果月份发生变化,要更新nestedcollectionView,我在方法(属于mainCollectionView )中使用了nestedcollectionView.reloadData():
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_main", for: indexPath) as! cell_Main
let nested_CollectionView = cell.collectionView as! nestedCollectionView
.
.
.
nested_CollectionView.reloadData()
}好了!如果我滚动mainCollectionView__,应该更新nestedCollectionView (月份将被更改)。
我的问题是:代码运行良好,但它在这里使用reloadData()是正确的吗?它是否是一种昂贵的CPU工作,应用程序是否占用了太多的CPU?
发布于 2019-07-23 06:20:40
我没有使用表示一年中月份的嵌套集合视图,而是尝试创建一个主CollectionView,节数为12 (月数),每个节表示月份,在每个区段中,numberOfItemsInSection将是月天数。任何更新都可以在这里(不使用reloadData()):
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
}.finally当我们向下滚动到末尾部分时,我们会调用reloadData()来更新新的numberOfSections并转移到下一年。
https://stackoverflow.com/questions/57156965
复制相似问题