分享

iOS UICollectionView与UITableView

 叹落花 2015-06-24
共同点:都需要接受两个协议 并执行代理方法
不同点:初始化方法不同  UITableVIew可以用alloc 方法初始化
           而UICollectionView必须用下面方法初始化

 // 初始化瀑布流

 UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

    [flowLayout setItemSize:CGSizeMake(150,120)]; //设置每个cell显示数据的宽和高必须

    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);

    flowLayout.minimumInteritemSpacing = 0;

    flowLayout.minimumLineSpacing = 0;

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; //水平滑动

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; //控制滑动分页用

    

 

    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];

    [self.view addSubview:self.collectionView];

    self.collectionView.backgroundColor = [UIColor whiteColor];

    [self.collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@"COllectioncell"];

    [self.collectionView setDataSource:self];

    [self.collectionView setDelegate:self];

    [self.view addSubview:self.collectionView];

UICollectionView自己没有cell必须自己自定义 
而且在- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath这个方法里的 cell初始化的时候重用的时候唯一标识必须与初始化的时候那个标记保持一致

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多