6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UICollectionView must be initialized with a non-nil layout parameter

Posted at

なんか落ちる

UICollectionViewをコードで追加したところ、UICollectionView must be initialized with a non-nil layout parameterエラーが。。。

let collectionView = UICollectionView(frame: view.frame)
collectionView.delegate = self
collectionView.dataSource = self
view.addSubview(collectionView)

解決方法

コードでUICollectionViewを追加するときは、FlowLayoutをinit時に追加しなければならないらしい。

let flowLayout = UICollectionViewFlowLayout()
flowLayout.itemSize = CGSize(width: 100, height: 100)
let collectionView = UICollectionView(frame: view.frame, collectionViewLayout: flowLayout)
collectionView.delegate = self
collectionView.dataSource = self
view.addSubview(collectionView)

圧倒的油断。

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?