iOS: reload single cell of UICollectionView

后端 未结 5 1504
無奈伤痛
無奈伤痛 2021-01-11 19:21

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

UICollectionView update a single cell

I know that I ultimately want somethin

5条回答
  •  悲&欢浪女
    2021-01-11 20:21

    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.

    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) {}];
    

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

提交回复
热议问题