Obj-Swift
Obj-Swift

Reputation: 2942

Reloading subview (UICollectionview)

In my ViewController I have four subviews, i.e UITableView, UICollectionView, View with UILabels, and View that displays preview image for that item.

By selecting a row in tableview, I am able to change preview image and all labels. However I can not refresh the UICollectionView data. I tried this solution but it just removes and adds views and that changes the layout and preview image disappears.

All I want to do is refresh UICollectionView contents. Is there any simpler way to do this?

Upvotes: 3

Views: 3692

Answers (3)

ribeto
ribeto

Reputation: 2088

To refresh only a portion of the UICollectionView you could also call this:

[self.collectionView reloadItemsAtIndexPaths:@[indexPath]]

where indexPath is the cell you want to reload. You could include multiple index paths in the array as well. To reload the entire first section you could call this:

NSIndexSet *sections = [NSIndexSet indexSetWithIndex:0];
[self.collectionView reloadSections:sections];

Upvotes: 1

tom
tom

Reputation: 19163

Assuming you have correctly hooked up your UICollectionView to a dataSource (UICollectionViewDataSource), you can call [myCollectionView reloadData] to make your collection view call your dataSource's methods (as below) to refresh itself:

– collectionView:numberOfItemsInSection:
– numberOfSectionsInCollectionView:
– collectionView:cellForItemAtIndexPath:
– collectionView:viewForSupplementaryElementOfKind:atIndexPath:

Upvotes: 0

robhasacamera
robhasacamera

Reputation: 3346

Have you tried [self.collectionView reloadData]; ?

Upvotes: 7

Related Questions