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初始化的时候重用的时候唯一标识必须与初始化的时候那个标记保持一致
  • 相关阅读:
    FastDFS--storage文件上传和下载问题
    Ubuntu18.04中安装virtualenv和virtualenvwrapper
    详解文件包含漏洞
    pikachu-数字型注入-sqlmap
    sqlmap命令手册
    SQL注入详解及技巧
    Linux中更新firefox
    DVWA-SQL注入
    CTF杂项题解题思路
    ubuntu搭建环境
  • 原文地址:https://www.cnblogs.com/longyun/p/3732508.html
Copyright © 2011-2022 走看看