0

I have a UIViewController with a UIBarButtonItem "Edit".When I tap "Edit" I push another controller with some data.I have 2 UICollectionView inside my controller and they scroll to cells with a specific NSIndexPath.For example in this image: enter image description here

It works if I can see cells (from 1.0/5.0 to 2.5/5.0) but if the item of my IndexPath is 6 for example, my collectionView scrolls to the 6th cell (4.0/5.0) but it doesn't select it, and I got this result(as you can see cell's background is not black, so it is not selected):

enter image description here

This is my code:

var index = NSIndexPath(item: indexPathSelected.item, section: 0)
ratingCollectionView.collectionView.selectItem(at: index as IndexPath, animated: true, scrollPosition: .centeredHorizontally)
ratingCollectionView.collectionView(collectionView, didSelectItemAt: index as IndexPath)
Andrea Toso
  • 287
  • 4
  • 12
  • 1
    you need to show code! simply based on the description you can do **a lot** of things wrong. – luk2302 Nov 28 '16 at 15:49
  • Did you try `self.collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem:indexPathSelected.item, inSection:0), atScrollPosition: .CenteredHorizontally, animated: true)`? – Nat Nov 28 '16 at 15:55
  • Possible duplicate of [UICollectionView auto scroll to cell at IndexPath](http://stackoverflow.com/questions/15985574/uicollectionview-auto-scroll-to-cell-at-indexpath) – Nat Nov 28 '16 at 15:56
  • Thank you, I missed view.layoutIfNeeded() in viewWillAppear.Now it works! – Andrea Toso Nov 28 '16 at 16:01

0 Answers0