CHTCollectionViewWaterfallLayout icon indicating copy to clipboard operation
CHTCollectionViewWaterfallLayout copied to clipboard

Option to provide alternative layout delegate

Open nicolaidahl opened this issue 11 years ago • 1 comments

In our app, we use this brilliant waterfall layout together with several other collectionview layouts depending on the state of our view controller. We dynamically switch the collection view layouts and are experiencing problems with the way the CHTCollectionViewWaterfallLayout determines its delegate. It uses the delegate of the collectionView.

The problem is that we do not only have to change the layout of the collectionView dynamically, we also change the delegate and dataSource of the collectionView dynamically because different layouts require different behavior.

We change the delegate and dataSource of the collectionView and then we change the layout before calling reload (on the collectionview).

Now, during this dynamic change, the CHTCollectionViewWaterfallLayout gets called by UIKit a few times to prepare for the transition, but now the delegate of the collectionView has been set to an instance that does not conform to the CHTCollectionViewWaterfallLayoutDelegate protocol. This causes crashes on the following line in prepareLayout:

CGSize itemSize = [self.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath];

If the CHTCollectionViewWaterfallLayout allowed me to specify a delegate explicitly I would not have this problem. Maybe a specific delegate could be specified in some initializer. If none is provided, the layout defaults to the collectionview's delegate

nicolaidahl avatar Dec 29 '14 15:12 nicolaidahl

I understand. But UICollectionViewFlowLayout also uses its collection view's delegate as its delegate, I'm not sure if it is reasonable not to use the same delegate object.

chiahsien avatar Apr 12 '15 14:04 chiahsien