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.
Asked
Active
Viewed 6,697 times
1
-
Have you tried it yourself? Post the code and describe the errors. – Difster Aug 05 '17 at 23:30
1 Answers
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
-
3Worth 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
-