首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS: indexPath.row、UICollectionView和图像

iOS: indexPath.row、UICollectionView和图像
EN

Stack Overflow用户
提问于 2013-04-06 09:00:12
回答 1查看 303关注 0票数 1

我正试图通过UICollectionView在我的主屏幕上只显示9张图片。但我对显示有问题。我的第一张图片总是重复两次(在第一行的位置1和位置2)。

我的代码有什么问题吗?

代码语言:javascript
运行
复制
// 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;

    }
EN

回答 1

Stack Overflow用户

发布于 2013-07-03 22:07:13

您不需要指定UICollectionView中有多少个区段吗?你已经有了委托方法numberOfItemsInSection,对吧?现在,在numberOfSectionsInCollectionView委托方法中,您是否指定了1?如下所示:

  • (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {返回1;//如果只有9张图片}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15845864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档