iOS UICollectionView與UITableView

來源:互聯網
上載者:User

標籤:class   c   color   int   a   資料   

共同點:都需要接受兩個協議 並執行代理方法不同點:初始化方法不同  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初始化的時候重用的時候唯一標識必須與初始化的時候那個標記保持一致

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.