Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionViewController的单元格不';不显示_Ios_Swift_Uicollectionview - Fatal编程技术网

Ios UICollectionViewController的单元格不';不显示

Ios UICollectionViewController的单元格不';不显示,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,代码9.2,Swift 4 我在Main.storyboard中有一个CollectionViewController场景,该场景链接到CollectionVewController类。 在这个场景中有一个单元格,其标识符是TextCell。我直接在Main.storyboard中更改了这张照片的背景色 这是我的CollectionViewControllerClass的代码 import UIKit private let reuseIdentifier = "TextCell" clas

代码9.2,Swift 4 我在Main.storyboard中有一个CollectionViewController场景,该场景链接到CollectionVewController类。 在这个场景中有一个单元格,其标识符是TextCell。我直接在Main.storyboard中更改了这张照片的背景色

这是我的CollectionViewControllerClass的代码

import UIKit

private let reuseIdentifier = "TextCell"

class CollectionViewController: UICollectionViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        // Register cell classes
        self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

        self.collectionView?.backgroundColor = UIColor(red: 52.0 / 250.0, green: 63.0 / 250.0, blue: 77.0 / 250.0, alpha: 1)
    }

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }

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

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)

        // Configure the cell
        return cell
    }
}
我运行应用程序时没有看到任何单元格,有人知道为什么吗?谢谢

删除这一行:

self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
这句话告诉运行时不要从情节提要中获取单元格。但您确实希望从情节提要中获取单元格,因为在那里您更改了单元格的背景色。

删除这一行:

self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
这句话告诉运行时不要从情节提要中获取单元格。但是您确实希望从情节提要中获取单元格,因为在那里您更改了单元格的背景颜色