3

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?

Community
  • 1
  • 1
Obj-Swift
  • 2,802
  • 3
  • 29
  • 50

3 Answers3

7

Have you tried [self.collectionView reloadData]; ?

robhasacamera
  • 2,967
  • 2
  • 28
  • 41
1

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];
ribeto
  • 2,038
  • 1
  • 16
  • 17
0

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:
tom
  • 18,953
  • 4
  • 35
  • 35
  • Hey Tommy. Yes everything was hooked up fine and i could load data in UICollectionView when VC loads for the first time. It only did not work when i tried to change item from within that ViewController. But it worked fine with the solution below. i.e [self.collectionView reloadData];. Thanks.. – Obj-Swift Dec 19 '12 at 23:08