Setting a UICollectionViewLayout subclass in a storyboard
cocoa-touch, ios, uicollectionview, uicollectionviewlayout, uistoryboard
Solution
The approach you've used would usually let you change the class of an instance in a storyboard. However, for a `UICollectionView`, you need to do something slightly different.
Instead of selecting the `UICollectionViewLayout` instance itself and adjusting its custom class parameter, select the `UICollectionView` instance, as show in this screen grab:
Now, in the storyboard inspector, select the "Attributes" inspector pane for the `UICollectionView` instance. You'll see something like this:
You need to change the "Layout" field combo box so that instead of "Flow" being selected, "Custom" is selected. A text field will then be appear to set your `UICollectionViewLayout` custom subclass, like this:
Problem
I'm using a storyboard for my project and I want to have a scene that's a `UICollectionViewController` sub class, who's `UICollectionView` uses a `UICollectionViewLayout` subclass. I've set this up in a storyboard, and I'm trying to change the "Custom Class" of the collection view's layout instance. Here's a screen grab of the layout object that I have selected in the storyboard: Here's a screen grab of storyboard's "Identity" inspector pane showing the "Custom Class" field that I am changing (it's at the top): When I try to change the "Custom Class", I can change type stuff in, but after saving, the it reverts back to being the default `UICollectionViewFlowLayout`. If I run the project, the default `UICollectionViewFlowLayout` gets used even though it's not the custom class I have set. How can I set a custom layout class, please?