美文网首页
tableViewCell内放置collectionView

tableViewCell内放置collectionView

作者: BigBossZhu | 来源:发表于2016-12-19 17:25 被阅读44次

tableView内部加载collectionView

  1. 注意tableView行高可以通过计算手动设定,通过数组数据,不要通过cell内部来计算,这样会存在复用的问题.
    产生了bug.

  2. 内部的collectionView存在的数据错乱的问题,需要在数据源set方法内舒心collectionView这样可以避免sh

#import <UIKit/UIKit.h>

@interface LMCollectionFlowLayout : UICollectionViewFlowLayout
/**
 collectionView的真实高度
 */
@property (assign,nonatomic) CGFloat collectionViewHeight;
@end

/// 此方法可以截取到flowLayout帮我们自动计算好的所有collectionView的item的frame信息
-(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray<UICollectionViewLayoutAttributes *> *itemArr = [super layoutAttributesForElementsInRect:rect];

    // 获取最后一行的item的最大y值
    self.collectionViewHeight = CGRectGetMaxY(itemArr.lastObject.frame);
    return itemArr;
}
流布局item
    self.minimumLineSpacing = 7.5;
    self.itemSize = CGSizeMake(50, 50);
    self.minimumInteritemSpacing = (ScreenWidth -2*38 - 50*4)/3;

创建文件需要的配置collectionView,注意创建的时候一定要配置流布局对象不然就会崩
  self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerNib:[UINib nibWithNibName:CellIdentifier bundle:nil] forCellWithReuseIdentifier:CellIdentifier];
    self.collectionView.backgroundColor = [self setGBRWithR:249 andG:249 andB:249];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.bounces = NO;

出现状况:本来应该每行显示三个结果显示两个.

  • 原因:


    Snip20161018_8.png

相关文章

网友评论

      本文标题:tableViewCell内放置collectionView

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