[英]iOS: indexPath.row, UICollectionView, and Images
我正在嘗試通過UICollectionView
在我的主iPhone屏幕上僅顯示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;
}
您是否不需要指定UICollectionView中有多少節? 您已經有了委托方法numberOfItemsInSection,對嗎? 現在,在numberOfSectionsInCollectionView委托方法中,您是否指定了1? 如:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.