我,我有細胞的每一行後繼承UICollectionViewController.
UICollectionView標題重複每一行
UITableView
標題重複。 我需要頭是「單」,並始終在屏幕的頂部(如導航欄)。
我用下面的代碼: 我UICollectionViewController
類:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return [categoryArray count]/2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CategoryCell" forIndexPath:indexPath];
CategoryViewModel *category = [categoryArray objectAtIndex:(indexPath.section*2 + indexPath.row)];
cell.name.text = category.name;
cell.image.image = category.image;
return cell;
}
-(UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if(headerIndexPath == nil){
headerIndexPath = indexPath;
}
CategoryScreenHeader *categoryScreenHeader = [collectionView dequeueReusableSupplementaryViewOfKind:
UICollectionElementKindSectionHeader withReuseIdentifier:@"CategoryScreenHeader" forIndexPath:headerIndexPath];
categoryScreenHeader.headerName.text = @"Some title";
categoryScreenHeader.headerImage.image = [UIImage imageNamed:@"step-0.png"];
return categoryScreenHeader;
}
謝謝。
你使用什麼佈局? – chris
我正在使用UICollectionViewLayout –