【发布时间】:2018-07-12 06:51:49
【问题描述】:
我想修复第一个单元格。
所以,我做了2个部分,这样写
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if(section == 0){
return 1;
}else{
return self.assetsFetchResults.count;
}
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 2;
}
#pragma mark - UICollectionViewDelegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
// NSInteger currentTag = cell.tag + 1;
//
// cell.tag = currentTag;
// NSLog(@"cell tag %d" , cell.tag);
if(indexPath.section == 0){
PhotoLibraryFirstCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoLibraryFirstCell" forIndexPath:indexPath];
return cell;
}else{
PhotoLibraryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoLibraryCell" forIndexPath:indexPath];
PHAsset *asset = self.assetsFetchResults[indexPath.item];
[self.imageManager requestImageForAsset:asset
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
// cell.imageView.image = result;
}];
return cell;
}
但是如果我这样写
在 0 节和 1 节之间创建空间,就像这张图片一样。
如何附加第 0 节和第 1 节?
【问题讨论】:
-
在我看来,您应该将所有单元格放在一个部分中。而不是检查
indexPath.section == 0,你应该检查indexPath.item == 0。
标签: ios objective-c collectionview