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

查看:1265
本文介绍了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天全站免登陆