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

前端 未结 2 832
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 17:54

I am trying to create a Facebook messenger like application from a youtube tutorial. I have a home page where the user click BarButton to open the chats. The Home page works

相关标签:
2条回答
  • 2020-12-20 18:27

    Probably when you present your ChatViewController you have something like:

    let chatVC = ChatViewController()

    But according to Apple doc:

    class UICollectionViewController

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

    So you need:

     let chatVC = ChatViewController(collectionViewLayout: UICollectionViewFlowLayout())
    
    0 讨论(0)
  • 2020-12-20 18:35

    Seems like you skipped steps in a tutorial which is using Interface Builder.

    The problem is, that in your ChatViewController there is a missing connection between your "collectionView?" and the corresponding UICollectionView (so called referencing outlet) in the Interface Builder.

    This is a very basic task in iOS development. Please have a look at the official Apple documentation under the topic "Create Outlets for UI Elements": Connect UI to Code

    0 讨论(0)
提交回复
热议问题