我正试图通过UICollectionView
在我的主屏幕上只显示9张图片。但我对显示有问题。我的第一张图片总是重复两次(在第一行的位置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;
}
发布于 2013-07-03 22:07:13
您不需要指定UICollectionView中有多少个区段吗?你已经有了委托方法numberOfItemsInSection,对吧?现在,在numberOfSectionsInCollectionView委托方法中,您是否指定了1?如下所示:
https://stackoverflow.com/questions/15845864
复制相似问题