I want to have a UICollectionView that scrolls from right to left, i.e. when it appears on the screen after loading, the right cells / elements should be displayed in the collection view first, and then add the rest to the left. I tried the workaround presented here , however, if I call it in viewWillAppear: I get:
*** Assertion failure in -[UICollectionViewData layoutAttributesForItemAtIndexPath:], /SourceCache/UIKit/UIKit-2372/UICollectionViewData.m:485
If I scroll the last item in viewDidAppear: it works fine, but now the user sees the left items first, and then scrolls to the last item. I also tried to use the contentOffset property in the UICollectionView (as a subclass of UIScrollView), but this parameter is also set only between the viewWillAppear: and viewDidAppear:
Any alternatives? I guess I could try to subclass UICollectionViewFlowLayout and arrange the cells from right to left, but I want to get into this territory a bit.
This is what I do:
- (void)_scrollToTheRight { NSIndexPath *lastIndexPath = [self.fetchedResultsController indexPathForObject:self.fetchedResultsController.fetchedObjects.lastObject]; if (lastIndexPath) { [self.collectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionRight animated:NO]; } }
Each value:
lastIndexPath (NSIndexPath *) $0 = 0x1f1754a0 <NSIndexPath 0x1f1754a0> 2 indexes [0, 21] (NSInteger)[self.fetchedResultsController.fetchedObjects count] (NSInteger) $3 = 22 [no Objective-C description available] (NSInteger)[self.collectionView numberOfItemsInSection:0] (NSInteger) $2 = 22 [no Objective-C description available]
Last note: The collection view controller is loaded from the container view (new in iOS 6 storyboards) of the view controller, which is placed on the screen using the UIPageViewController.
Thanks.
EDIT 1: Therefore, I believe the problem is that using the layout layout ( UICollectionViewController implemented using the new Container Views) is causing the problem.
Because elsewhere in the application, where I will also embed view controllers (normal UITableViewController ) viewDidAppear: is called before the view. I suspect that this setting does not notify each child view controller correctly that they should load and compose their views.