共同點(diǎn):都需要接受兩個(gè)協(xié)議 并執(zhí)行代理方法
不同點(diǎn):初始化方法不同 UITableVIew可以用alloc 方法初始化
而UICollectionView必須用下面方法初始化
// 初始化瀑布流 UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setItemSize:CGSizeMake(150,120)]; //設(shè)置每個(gè)cell顯示數(shù)據(jù)的寬和高必須 flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); flowLayout.minimumInteritemSpacing = 0; flowLayout.minimumLineSpacing = 0; [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; //水平滑動(dòng) [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; //控制滑動(dòng)分頁用
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這個(gè)方法里的 cell初始化的時(shí)候重用的時(shí)候唯一標(biāo)識(shí)必須與初始化的時(shí)候那個(gè)標(biāo)記保持一致
|
|