Hey guys, when I run my project the error: 'UICollectionView must be initialized with a non-nil layout parameter', appears. I don't know why because I already used the same code in another project and it worked.
This is my code:
Thanks in advance!
This is my code:
Code Block var myCollectionView : UICollectionView? func setUpContactsCollectionView() { let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) layout.itemSize = CGSize(width: 100, height: 100) layout.scrollDirection = .horizontal myCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout) myCollectionView?.showsHorizontalScrollIndicator = false myCollectionView?.register(InserateCollectionCell.self, forCellWithReuseIdentifier: "InserateCollectionCell") myCollectionView?.backgroundColor = UIColor.white myCollectionView?.dataSource = self myCollectionView?.delegate = self myCollectionView?.translatesAutoresizingMaskIntoConstraints = false myCollectionView?.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true myCollectionView?.topAnchor.constraint(equalTo: topAnchor, constant: 50).isActive = true myCollectionView?.widthAnchor.constraint(equalTo: widthAnchor).isActive = true myCollectionView?.heightAnchor.constraint(equalTo: heightAnchor).isActive = true }
Thanks in advance!