0
私はUICollectionViewをUIView内に追加してアイテムを追加しましたが、アイテムがコレクションビューに表示されない理由を理解できないようです。ここで私がこれまで持っているものです。Collectionビューでセルが返されない(Swift 3)
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView!.delegate = self
self.collectionView!.dataSource = self
self.collectionView.backgroundColor = UIColor.green
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! CollectionViewCell
cell.itemImage.image = UIImage(named: "banana.png")
cell.itemName.text = "banana testing"
return cell
}
私は色を変更するにはコレクションビューの背景を得ることができますが、何らかの理由でそれがコレクションビュー内の項目に移入されません。任意のヒントをいただければ幸いです。私はしばらく前に答えを見つけたと私は答えを掲示した場合、それが最善だと思っ
DispatchQueue.main.async {
self.collectionView.reloadData()
}
画像名が正しいことを確認してください。 – Xcoder
リロードをどこで呼びましたか? viewDidLoadでは? – HAS
デバッグでは、collectionViewセルの表示を色分けしてみてください。 –