我,我有细胞的每一行后继承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 –