Switch UICollectionView between layouts with different data sources

I struggled with the transition between layouts, view controllers, collectible views and their animations for a while. My goal at the moment is to copy some of the features of the iOS Photos app: moving from a view with many stacks to a view with only those things in 1 stack.

So, I created a collection view with 4 stacks. You can go to LineLayout by clicking or holding them. Now the hard part for me is the transition between the CollectionViewController with one data source (which informs it of all 4 sections) to another data source (which shows only one section).

Here's the transition code in the helper method:

- (UICollectionViewController *)nextViewControllerForIndexPath: (NSIndexPath *)indexPath
{
    LineLayout *layout = [[LineLayout alloc] init];

    APLGridCollectionViewController *nextCollectionViewController =
    [[APLGridCollectionViewController alloc] initWithCollectionViewLayout:layout];
    nextCollectionViewController.collectionView = self.collectionView;
    nextCollectionViewController.collectionView.dataSource = nextCollectionViewController;
    nextCollectionViewController.selectedSection = indexPath.section;

    nextCollectionViewController.useLayoutToLayoutNavigationTransitions = YES;

    nextCollectionViewController.title = @"Line Layout";

    return nextCollectionViewController;
}

nextCollectionViewController collectionView self, dataSource CollectionViewController 4 .

, :

2014-06-25 13:37:00.774 CollectionViewTransition[743:142104] *** Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:], /SourceCache/UIKit/UIKit-3232.3/UICollectionViewData.m:556
2014-06-25 13:37:00.775 CollectionViewTransition[743:142104] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 3 when there are only 1 sections in the collection view'

... , -. , ?

, , , , , EXC_BAD_ACCESS, 7 .

. WWDC, , - .

+4

Source: https://habr.com/ru/post/1546051/


All Articles