ios - UICollectionView dequeueReusableCellWithReuseIdentifier :forIndexPath: wrong indexPath reuse cell

标签 ios uicollectionview reloaddata

登录方式:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

第一次加载数据

2016-09-30 15:55:28.764 MYAPP[12950:384498] PosterCell-0: <PosterCell: 0x7fdd3c57cf90>

2016-09-30 15:55:28.782 MYAPP[12950:384498] PosterCell-1: <PosterCell: 0x7fdd3c4cc0c0>

2016-09-30 15:55:28.807 MYAPP[12950:384498] PosterCell-2: <PosterCell: 0x7fdd3c5815e0>

第二次重新加载数据

2016-09-30 15:55:28.959 MYAPP[12950:384498] PosterCell-0: <PosterCell: 0x7fdd3c5815e0>

2016-09-30 15:55:28.961 MYAPP[12950:384498] PosterCell-1: <PosterCell: 0x7fdd3c57cf90>

2016-09-30 15:55:28.962 MYAPP[12950:384498] PosterCell-2: <PosterCell: 0x7fdd3c4cc0c0>

你看,不同的 XRKPosterCell-0 在两次加载中。为什么?

最佳答案

那是因为您正在重用使用 dequeueResuableCell 创建的单元格。

也比较其他单元格的重新加载 1 和重新加载 2 ...您可以观察到

postercell-0 in reload1  = postercell1 in reload2
PosterCell-1 in reload1 = PosterCell-2 in reload2
PosterCell-2 in reload1 = PosterCell-0 in reload2.

细胞刚刚被重复利用!

关于ios - UICollectionView dequeueReusableCellWithReuseIdentifier :forIndexPath: wrong indexPath reuse cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39786585/

相关文章:

ios - 如何使用 Swift 3 在 iOS 9 中设计表单布局

ios - [ TableView 重新加载数据];在导航回根 Controller 之前不会重新加载

ios - 如果从 nib 加载,则 UITableViewCell 框架与 Storyboard 加载有所不同

ios - TableView 在executeFetchRequest 后未重新加载

ios - 为什么我的 [tableview reloadData] 执行得太晚了?

ios - 在 Objective-C 中的按钮文本中显示数组元素

ios - 我的通话错误 : Incorrect Argument Label In Call (have 'key:' , 预期为 'coder:' )

ios - 如何在 Xcode Interface Builder 中使用约束/自动布局来正确缩放图像和字体?

ios - 从 UIViewController 启动 UICollectionView

ios - xcode 7 和 cloudkit 的非常奇怪的问题