美文网首页
UICollectionView的cell创建直接从第三个数据开

UICollectionView的cell创建直接从第三个数据开

作者: 未来可期me | 来源:发表于2017-10-26 10:58 被阅读19次

实现的效果是这样

lALPBbCc1RKmEL_NBTbNAu4_750_1334.png_620x10000q90g.jpg

大概意思就是第一组没有数据就直接将改组的cell高度变成0
效果实现了,但是第二组数据创建cell就出问题了--奇葩问题

lALPBbCc1RKmELnNBTbNAu4_750_1334.png_620x10000q90g.jpg
  • 代码问题在这
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section == 0) {
        
        if (self.couponDataArr.count) {
            return CGSizeMake(SCREEN_WIDTH, AUTO_SCALE_H(103));
        }else{
            
            return CGSizeMake(SCREEN_WIDTH, 0);
        }

    }else if(indexPath.section == 1){
        return CGSizeMake((MainScreenWidth- 10)/2, (MainScreenWidth- 10)/2+98);
    }else{
        return CGSizeZero;
    }
}

就这样加个.1就好了

lALPBbCc1RKmEM_NBTbNAu4_750_1334.png_620x10000q90g.jpg
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section == 0) {
        
        if (self.couponDataArr.count) {
            return CGSizeMake(SCREEN_WIDTH, AUTO_SCALE_H(103));
        }else{
            
            return CGSizeMake(SCREEN_WIDTH, 0.1);
        }

    }else if(indexPath.section == 1){
        return CGSizeMake((MainScreenWidth- 10)/2, (MainScreenWidth- 10)/2+98);
    }else{
        return CGSizeZero;
    }
}


三张图,应该很是明了

相关文章

网友评论

      本文标题:UICollectionView的cell创建直接从第三个数据开

      本文链接:https://www.haomeiwen.com/subject/gfihpxtx.html