我正在子类化UICollectionViewController.
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;
}
谢谢你。