Yinghao Wang Yinghao Wang - 9 months ago 35
iOS Question

Why does UICollectionView conform to UICollectionViewDelegateFlowLayout by default?

I'm just confused with the following code that gets executed in a

instantiated from a xib file:

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;

which is declared in the protocol
. However, there is nowhere in the
showing that it would conform to this protocol, as declared in the

NS_CLASS_AVAILABLE_IOS(6_0) @interface UICollectionViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource>

Can anyway explain why
would conform to


By default, the class of a collection view's layout when dragged into a xib/storyboard is UICollectionViewFlowLayout, which is why by default the delegate methods for UICollectionViewDelegateFlowLayout are called. If you were to change the layout object's class in the xib/storyboard, none of the methods specific to UICollectionViewDelegateFlowLayout would be called.

Also, UICollectionViewController may privately conform to UICollectionViewDelegateFlowLayout, or it may not. It doesn't really matter because a class doesn't technically have to explicitly conform to a protocol in order to implement and respond to methods in that protocol.