zoukankan      html  css  js  c++  java
  • iOS UICollectionView与UITableView

    共同点:都需要接受两个协议 并执行代理方法
    不同点:初始化方法不同  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初始化的时候重用的时候唯一标识必须与初始化的时候那个标记保持一致
  • 相关阅读:
    ElasticSearch搜索引擎安装配置拼音插件pinyin
    ElasticSearch搜索引擎安装配置中文分词器IK插件
    Linux系统中ElasticSearch搜索引擎安装配置Head插件
    阿里云服务器Linux系统安装配置ElasticSearch搜索引擎
    盒子模型
    div与span的区别
    .与localhost与 .sqlexpress的区别
    C#-多态
    C#-里氏转换
    C#-继承
  • 原文地址:https://www.cnblogs.com/longyun/p/3732508.html
Copyright © 2011-2022 走看看