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初始化的时候重用的时候唯一标识必须与初始化的时候那个标记保持一致
  • 相关阅读:
    关于dllimport的使用
    公众平台返回原始数据为: 错误代码-40164
    CentOS7.4 系统下 Tomcat 启动慢解决方法
    PyCharm实现高效远程调试代码
    代码比较工具推荐
    CentOS7 下源码安装 python3
    linux定时任务调度定系统——opencron
    使用 ISO镜像配置 本地yum 源(RHEL, CentOS, Fedora等适用)
    Error: rpmdb open failed
    部署Redis(脚本安装)
  • 原文地址:https://www.cnblogs.com/longyun/p/3732508.html
Copyright © 2011-2022 走看看