-1
最初に私はストーリーボードを使用していません。これはすべてプログラムで行います。呼び出されていない。それは何が原因でしょうか?スウィフトコレクションビューコントローラーのセルが表示されず、アイテムのセルが呼び出されていない
import UIKit
class ChatLOGVC: UICollectionViewController {
private let cellId = "Cell"
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.red
collectionView?.register(FriendCell.self, forCellWithReuseIdentifier: cellId)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
print("cell for item at index path called")
return collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize.init(width: view.frame.width, height: 80)
}
}
class FriendCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.blue
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
}
あなたはレイアウトパラメータを使用してコレクションVCを初期化しますか? – Phyber
@Phyber - UICollectionViewDelegateFlowLayoutを追加すると、全く同じ結果が得られます。/何もしませんか? – bennypalmer661
ストーリーボードを使用していますか? – Phyber