Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change label value in UICollectionView without reload data?

I'm using swift 2.2 and i have a collectionview inside cell ia hve a label.I want to change a label text value in UICollection view on a button click without using reloading whole uiCollection view. I can't use collectionView.reloadData() for my scenario. I want a do it without using it. Just to update one label in a particular item in collectionview. Any help??

like image 207
Anushka Madushan Avatar asked Mar 31 '17 09:03

Anushka Madushan


2 Answers

If you pass the IndexPath you can access the cell, then from it you can change the label using this syntax

let cell = self.collectionView.cellForItem(at: IndexPath) as? yourCollectionViewCellName
cell.label.text = "new text"
like image 87
Albi Avatar answered Oct 21 '22 03:10

Albi


You can do it by this way:

let indexPath = NSIndexPath(forRow: row, inSection: 0)
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

It will not reload your complete UICollectionView.

like image 20
Dheeraj D Avatar answered Oct 21 '22 02:10

Dheeraj D