<分区>
Xcode 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
}
}
我在运行该应用程序时没有看到任何单元格,有人知道为什么吗?谢谢!