我正在尝试在我的主iPhone屏幕上显示UICollectionView
仅9张图片。但我的显示有问题。我的第一张照片总是重复2次(第1行和第1行的第2位)。
我的代码有问题吗?
// Define the number of Cell.
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 9; }
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *IdCell = @"Cell";
SSCollectionViewCell *cell = (SSCollectionViewCell *) [collectionView dequeueReusableCellWithReuseIdentifier: IdCell forIndexPath: indexPath];
int imageNumber = indexPath.row % 9;
cell.imageView.image = [UIImage imageNamed: [NSString stringWithFormat:@"M2_img_%d@2x.png", imageNumber]];
return cell;
}
答案 0 :(得分:0)
您是否需要指定UICollectionView中有多少个部分?你已经拥有了委托方法numberOfItemsInSection,对吧?现在,在numberOfSectionsInCollectionView委托方法中,你指定了1吗?如: