iOS:重新加载 UICollectionView 的单个单元格 [英] iOS: reload single cell of UICollectionView

查看:25
本文介绍了iOS:重新加载 UICollectionView 的单个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关注以下关于在 UICollectionView 中重新加载单元格的帖子:

I am trying to follow the following post on reload a cell in a UICollectionView:

UICollectionView 更新单个单元格

我知道我最终想要这样的东西:

I know that I ultimately want something that looks like this:

[self.collectionView reloadItemsAtIndexPaths:??];

但我不知道如何查找和传递特定单元格的 indexPath.有没有人可以指点一下?

But I don't know how to find and pass the indexPath of a particular cell. Can anyone provide any pointers?

我有一个 NSMutableArray,其中包含所有单元格信息(在每个单元格中生成的 imageViews).理想情况下,我想做的是传递 NSMutableArray 的索引来刷新页面上的相应单元格.但我不确定数字索引是如何转换为 indexPath 的.

I have an NSMutableArray that contains all the cell information (imageViews that are generated in each cell). Ideally, what I'd like to do is pass the index of the NSMutableArray to refresh the corresponding cell on the page. But I'm not sure how the numerical index gets translated into an indexPath.

提前感谢您的帮助!

推荐答案

这取决于您的实现以及您如何将单元格分组为部分,但假设您有一个部分,并且数组中的每个元素对应于您的表.

It depends on your implementation and how you have grouped your cells into sections but let's assume you have one section and each element in your array corresponds to a row in your table.

如果您想重新加载与索引 x 处的数组元素对应的单元格,您需要做的就是编写

If you wanted to reload a cell corresponding to an array element at index x all you need to do is write

[_collectionView performBatchUpdates:^{
    [_collectionView reloadItemsAtIndexPaths:@[[NSIndexPath x inSection:0]]];
} completion:^(BOOL finished) {}];

相反,如果你有单元格但想找到它的索引路径,你可以随时调用 [collectionView indexPathForCell:myCell]

Conversely, if you have the cell but want to find its index path you can always call [collectionView indexPathForCell:myCell]

这篇关于iOS:重新加载 UICollectionView 的单个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆