首页 > 移动平台 > 详细

iOS UICollectionView与UITableView

时间:2014-05-18 20:25:01      阅读:493      评论:0      收藏:0      [点我收藏+]
共同点:都需要接受两个协议 并执行代理方法
不同点:初始化方法不同  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初始化的时候重用的时候唯一标识必须与初始化的时候那个标记保持一致

iOS UICollectionView与UITableView,布布扣,bubuko.com

iOS UICollectionView与UITableView

原文:http://www.cnblogs.com/longyun/p/3732508.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!