小编Ron*_*hiv的帖子

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

我试图从youtube教程创建一个像Facebook应用程序的应用程序.我有一个主页,用户单击BarButton打开聊天.主页工作正常,直到我单击BarButton打开聊天,它崩溃时出现以下错误消息"UICollectionView必须使用非零布局参数初始化".我是iOS开发的新手,所以无法真正理解问题究竟是什么,因为我已经有了init方法.我在AppDelegate中遗漏了一些东西,因为我有不同的观点,这很令人困惑:(.真的很感谢你的帮助.谢谢!

class ChatViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.title = "Chats"

    collectionView?.backgroundColor = UIColor.gray

            // Do any additional setup after loading the view.
}

override func viewWillAppear(_ animated: Bool)
{
    collectionView?.register(ChatCell.self, forCellWithReuseIdentifier: "cellID")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 3
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift swift3

5
推荐指数
1
解决办法
4515
查看次数

标签 统计

ios ×1

swift ×1

swift3 ×1

uicollectionview ×1