mardi 4 août 2015

UICollectionView and AutoLayout

I'm trying to create a UICollectionView whose width/height and coordinates are defined using AutoLayout (using SnapKit). When using the default UICollectionView constructor it fails with the following reason:

reason: 'UICollectionView must be initialized with a non-nil layout parameter'

The only constructor that allows a layout to be passed in, also requires a frame, so I tried using CGRectZero as the value for the frame like so:

collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)

I then used SnapKit to setup the constraints like so:

collectionView?.snp_makeConstraints { make -> Void in
        make.width.equalTo(view)
        make.height.equalTo(300)
        make.top.equalTo(someOtherView)
    }

However, when doing so the UICollectionView is never rendered. In fact, I do not see the data source being called at all.

Any thoughts on how to use AutoLayout with a UICollectionView or what I might be doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire