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,即可

  • 相关阅读:
    从零起步搭建Hadoop单机和伪分布式开发环境图文教程
    使用DOM技术操纵文档
    求数组的子数组之和的最大值
    设计时(DesignTime)和运行时(RunTime)的区别
    ubuntu上ssh客户端应用
    创建一个简单的基于MVC的Django项目
    终结点与服务寄宿
    Google文件系统(GFS)翻译学习
    模板引擎开发(二)值标签的处理
    移动App服务端架构设计
  • 原文地址:https://www.cnblogs.com/Apple2U/p/5666105.html
Copyright © 2011-2022 走看看