我在MainCollectionView swift文件中有以下代码:未调用cellForitemAt函数。我已删除函数sizeForitem,但未发生任何事情。将值更改为较小的值,但未发生任何事情。
import UIKit
MainViewController类:UICollectionViewController,UICollectionViewDelegateFlowLayout {
let cellID = "cellID"
override func viewDidLoad() {
super.viewDidLoad()
collectionView.backgroundColor = .blue
collectionView.register(MainCell.self, forCellWithReuseIdentifier: cellID)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath) as! MainCell
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 150)
}
}
MainCell类:UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.yellow
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
我在做什么错了?