zoukankan      html  css  js  c++  java
  • iOS Assertion failure in -[UICollectionViewData validateLayoutInRect:]

    使用UICollectionView时、滚动过程中发现崩溃报上面的错误,

    我的使用场景是这样的在tableviewcell上嵌套tableview1然后在tableview1的tableviewcell上嵌套CollectionView。

    collectionView滚动过程崩溃 布局与数据不符 原因是布局的缓存 但同样的场景tableview就没有这个问题

      解决办法:添加以下更新布局的代码

    [self.contentView setNeedsLayout];
    [self.contentView layoutIfNeeded];
    
    
    - (void)refreshImg:(NewTaskPointModel *)iCKTrendModel {
        NSInteger count = iCKTrendModel.pictures.count;
        if (count && count<= 9) {
            CGFloat   itemH = 70;
            NSInteger row = (count-1)/3;
            NSInteger collecH = (row + 1) * itemH + row*2;
            
            self.collectionView.hidden = NO;
            self.collectionViewHCons.constant = collecH;
            self.collectionViewWCons.constant = 214;
            self.collectionTopCons.constant = 10;
            
        } else {
            self.collectionView.hidden = YES;
            self.collectionViewHCons.constant = 0;
            self.collectionViewWCons.constant = 0;
            self.collectionTopCons.constant = 0;
        }
        
    //    滚动过程崩溃 布局与数据不符 原因是布局的缓存
    //    刷新数据
        [self.collectionView reloadData];
    //    更新布局
    // 立即执行更新
     [self.contentView setNeedsLayout];

      [self.contentView layoutIfNeeded];
        
    }
  • 相关阅读:
    jsp大文件(视频)上传问题
    python多版本的pip共存问题解决办法
    buntu系统安装rpm包的方法
    如何查看linux是32位还是64位
    python的if else
    python获取列表唯一值
    python列表转数组
    python文件操作write与writelines的区别
    python中字符串str的strip()方法
    ubuntu16.04安装cloudcompare及打开方法
  • 原文地址:https://www.cnblogs.com/lijianyi/p/11557691.html
Copyright © 2011-2022 走看看