且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:UICollectionView 必须使用非 nil 布局参数进行初始化

更新时间:2021-10-06 23:30:29

可能当你展示你的 ChatViewController 时,你会有类似的东西:

Probably when you present your ChatViewController you have something like:

让 chatVC = ChatViewController()

let chatVC = ChatViewController()

但根据 Apple 文档:

类 UICollectionViewController

当您初始化控制器时,使用 init(collectionViewLayout:) 方法,您指定集合视图应该具有的布局.

When you initialize the controller, using the init(collectionViewLayout:) method, you specify the layout the collection view should have.

所以你需要:

 let chatVC = ChatViewController(collectionViewLayout: UICollectionViewFlowLayout())