Search code examples
iosobjective-cuikituicollectionviewuicollectionviewcell

Label text in UICollectionViewCell not updating


I'm trying to change the text of a UILabel in a UICollectionViewCell after the UICollectionViewCell has loaded, when tapping a button. But the label doesn't update on the screen. The console shows that the text property of the label is updated, but it seems the label isn't redrawn with the new text.

Is this a known problem with UICollectionViewCells? Some kind of caching issue, perhaps? Do I need to reload the cell, or the entire collection view for the update to show?


Solution

  • Because the cell is already loaded, no change in cell will happen until it's reloaded, so you can either reload the entire collection view [self.collectionView reloadData];

    Or just one/multiple cell(s) that got affected with that change of data

    [self.collectionView reloadItemsAtIndexPaths: indexpathArray];

    But make sure that you change the data properly before reloading the cells