iOS:indexPath.row,UICollectionView和图像
问题描述:
我想通过UICollectionView
在我的主iphone屏幕上显示9张图片。但是我的显示有问题。我的第一张照片总是重复2次(位于第1行的位置1和位置2)。iOS:indexPath.row,UICollectionView和图像
我的代码有问题吗?
// 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_%[email protected]", imageNumber]];
return cell;
}
答
难道你不需要指定在UICollectionView中有多少部分?你已经有了委托方法numberOfItemsInSection,对吗?现在,在numberOfSectionsInCollectionView委托方法中,您是否指定了1?如:
- (NSInteger的)numberOfSectionsInCollectionView:(UICollectionView *)的CollectionView { 返回1; //如果它只是9图像 }
代码看起来不错...查看您的图像[email protected]&[email protected] – samfisher 2013-04-06 01:04:37
[评论为不准确取出] – Pinwheeler 2013-04-06 01:48:04
我的图片都OK和正确命名。 .. :( – 2013-04-06 08:37:17