I added UICollectionView
by code.
Now, the app crash with message: UICollectionView must be initialized with a non-nil layout parameter
.
Do
Can use UICollectionViewDelegateFlowLayout and don't forget to set your cell size
class YourViewController : UICollectionViewController, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize.init(width: view.frame.width, height: 250)
}
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
// initialized with a non-nil layout parameter
init() {
super.init(collectionViewLayout: UICollectionViewFlowLayout())
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}