zoukankan      html  css  js  c++  java
  • The number of sections contained in the collection view after the update (1) must be equal to the number of sections contained in the collection view before the update (0), plus or minus the number of

    现象:当删除CollectionView 当中的某个section的时候,报上面的错误

    初步分析:当前CollectionView删除前后都不止一个Section,怎么会报那样的错误;猜想可能是相册界面的另外两个UICollectionView,对当前的CollectionView有影响。

    初步验证:当加载了另外一个collectionView,再去删除原collectionView时并没有报错

    解决方案:ViewDidLoad的时候加载三个CollectionView

     

    再次分析:按道理应该是不会相互影响的,百度了一下之后发现通常出现这类问题是由于执行了增删操作之后,数据源返回的section数据和collectionView中的不一致, 检查代码numberOfSectionsInCollectionView 中 发现多了一个if(HasLoaded){  // do something; } else {  return 0; } 的判断;

    -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
        
        if (HasLoaded) {
            NSInteger type =0;
            for (NSInteger k=0; k<3; k++) {
                if (collectionView == self.collectionViewArray[k]) {
                    type = k;
                    break;
                }
            }
            NSInteger count = self.httpConnect.WifiConnected? self.dataModel.ListsArray[type].SectionArray.count: self.dataModel.LocalListsArray[type].SectionArray.count;
            if (count==0 && ![self.collectionViewArray[type] isHidden]) {
                
                self.noDataImageView.hidden = NO;
                self.noDataLabel.hidden = NO;
            }else {
                self.noDataImageView.hidden = YES;
                self.noDataLabel.hidden = YES;
            }
            return count;
        }
        else {
            return 0;
        }
    }

    当我加载了其他两个CollectionView之后,使HasLoaded为true了,所以之前的分析只是凑巧解决了那个问题。

    正确方案:去掉HasLoaded,即可

  • 相关阅读:
    数据库秒级平滑扩容架构方案
    利用SQL索引提高查询速度
    SQL Server调优系列进阶篇(如何维护数据库索引)
    SQL Server调优系列进阶篇(如何索引调优)
    SQL语法集锦一:显示每个类别最新更新的数据
    TreeView中节点勾选设置
    C# WinForm捕获全局异常
    SQL SERVER 查询死锁
    DataTable导入到Excel文件
    Microsoft SyncToy 文件同步工具
  • 原文地址:https://www.cnblogs.com/Apple2U/p/5666105.html
Copyright © 2011-2022 走看看