Reputation: 225
I am working on multiple UICollectionViewController
s that all show the same contents with different layouts.
According to Apple's CollectionViewTransition sample application and Session 218 of WWDC 2013, UICollectionViewController
has a property called useLayoutToLayoutNavigationTransitions
that basically handles navigation transitions by interpolating 'from' and 'to' collection view's layouts.
Let's assume that I have two UICollectionViewControllers
called MasterCollectionViewController and DetailCollectionViewController. When I push DetailCollectionViewController from MasterCollectionViewController, layout is properly changed, but collection view still uses the data source declared in MasterCollectionViewController.
This is a problem for me, because in each of UICollectionViewController
s, I need to rearrange section/item configurations. A good example of what I am trying to do is Photos application on iOS 7. The first tab of this application has three view controllers: years, collections, and moments. These view controller all show the same contents: photos. What's different between each view controller is how photos are grouped in section. And section grouping is the responsibility of UICollectionViewDataSource
which is an issue here.
If the behavior of useLayoutToLayoutNavigationTransitions
property that I am experiencing is a normal behavior, is there a way to achieve my goal in different approach?
Any help or comment would be appreciated.
Thanks!
Upvotes: 7
Views: 2387
Reputation: 10283
I'm seeing the same behaviour and agree it is less than ideal.
The fundamental issue here is that the same UICollectionView
instance is shared/passed between the two view controllers. I experimented with trying to change the delegate and datasource of the UICollectionView
but ran into various problems.
In the end, the solution I ended up adopting was to make the master UICollectionViewController
a delegate of the UINavigationController
, implementing:
– navigationController:willShowViewController:animated:
...using this to switch a controllerMode
property and then adding switch statements to -collectionView:cellForItemAtIndexPath:
and -collectionView:didSelectItemAtIndexPath:
to provide the required behaviour in the mode. I also added code to -setControllerMode:
to do any required state changes in the master view controller.
Hope that helps!
Upvotes: 6