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

  • 相关阅读:
    Linux系统下设置Tomcat开机自动启动
    2、nginx配置文件基本介绍
    1、Centos7下安装nginx
    40、springboot——运行状态监控使用Actuator
    39、springboot——热部署
    38、springboot——分布式之SpringCloud
    38、springboot——分布式之zookeeper+dubbo
    37、springboot——安全
    36、springboot——异步任务、定时任务、邮件任务
    React过誉了吗?
  • 原文地址:https://www.cnblogs.com/Apple2U/p/5666105.html
Copyright © 2011-2022 走看看