1

I've been struggling with this for awhile and can't find it answered elsewhere. Basically I need to edit a view inside the selected collection view cell. For example once a cell is clicked the label text inside that cell changes.

Here is what i need however it only works on tableviews

samson
  • 23
  • 1
  • 4

1 Answers1

11

If I understand it correctly you need to get the selected collection view cell:-

if let cell = collectionView.cellForItemAtIndexPath(indexPath) {
 cell.textlabel.text = "yourtext"
}
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • yes you understand correctly, however i've tried your code and it's not giving me access to the cells view such as the label. Instead i'm getting the cell's "backgroundView" , "contentView", etc.. – samson Aug 05 '17 at 20:33
  • Can you show me your code? And also check where you have added label inside it? – Hussain Shabbir Aug 05 '17 at 20:33
  • 3
    Worth noting that if you have subclassed your UICollectionViewCell you will need to append `as! MyCollectionViewCell` after `cellForItemAtIndexPath(indexPath)`, where MyCollectionViewCell is the name of your subclassed cell. – Tom Aug 05 '17 at 20:39
  • @Samson, follow Tom's comments that make sense if you have subclassed cell. – Hussain Shabbir Aug 05 '17 at 20:41
  • you bloody legends – samson Aug 05 '17 at 20:54