標籤: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初始化的時候重用的時候唯一標識必須與初始化的時候那個標記保持一致