Label text in UICollectionViewCell not updating

删除回忆录丶 提交于 2019-12-06 06:00:51

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

I had a similar situation where a UILabel in the collectionView cell was updating fine. Then after making some modifications to the storyboard, the UILabel would not change when updating the value programmatically. As noted in the initial question the value stayed the default value even though the debug terminal showed that the connected UILabel attribute text was being updated.

Here is how I resolved the issue. In the storyboard,

  1. Deleted the referencing outlet for the UILabel (in the "Show the connections Inspector")
  2. Deleted the UILabel from the storyboard
  3. Re-added the UILabel
  4. Reconnected the referencing outlet to the swift file code attribute

And somehow, everything started working fine again.

As a side note: The swift 3.1 versions of Radwa's answer are:

collectionView.reloadItems(at: [indexPath]) // single cell in the collection view
collectionView.reloadData() // entire collection view
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!