Ios UICollectionViewController的单元格不';不显示
代码9.2,Swift 4 我在Main.storyboard中有一个CollectionViewController场景,该场景链接到CollectionVewController类。 在这个场景中有一个单元格,其标识符是TextCell。我直接在Main.storyboard中更改了这张照片的背景色 这是我的CollectionViewControllerClass的代码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
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)
这句话告诉运行时不要从情节提要中获取单元格。但是您确实希望从情节提要中获取单元格,因为在那里您更改了单元格的背景颜色