How to subclass UICollectionViewFlowLayout with storyboard

I am using UICollectionView with a Storyboard and trying to subclass UICollectionViewFlowLayout, but it does not seem to work.

I created a subclass of CollectionViewFlowLayout :

 #import "CollectionViewFlowLayout.h" @implementation CollectionViewFlowLayout -(id)init { NSLog(@"Init of CollectionViewFlowLayout"); if (!(self = [super init])) return nil; self.itemSize = CGSizeMake(250, 250); return self; } @end 

And in the storyboard identification inspector, I changed the class for the stream layout:

Identity Inspector for Storyboard

But when I save / build / run, itemSize is not set to 250 and my NSLog is not output.

I saw in examples like this that you can set the layout in the collectionView controller, but I kind of assumed that it wasn’t necessary if you set it to the storyboard.

+7
source share
1 answer

Objects loaded from the storyboard use initWithCoder: rather than init . Instead, translate your installation code here or use the generic method that is called from each initializer.

+11
source

All Articles