Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Subclass UICollectionViewFlowLayout with Storyboard

I'm using a UICollectionView with Storyboard and trying to subclass the UICollectionViewFlowLayout but it doesn't seem to work.

I've created the subclass 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's Identity Inspector I changed the class for the flow layout:

Identity Inspector for Storyboard

But when I save/build/run, the itemSize is not set at 250 and my NSLog isn't being output.

I've seen in examples such as this that you can set the layout in the collectionView controller, but I sort of assumed that wasn't necessary if you set it in the storyboard.

like image 692
Callmeed Avatar asked Feb 21 '13 07:02

Callmeed


1 Answers

Objects loaded from the storyboard use initWithCoder:, not init. Move your setup code there instead, or have a common method that is called from each initialiser.

like image 193
jrturton Avatar answered Sep 22 '22 13:09

jrturton