CollectionViewの中身のコンポーネントを触ろうとするとクラッシュしてしまうのですが何が原因かわかりません。
error
エラーコードは以下のようにOptionalであると表示されていますが、cellの中には間違いなく@IBOutletで接続ができています
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
cell
class SampleCollectionViewCell: UICollectionViewCell { @IBOutlet weak var: UIView! override func awakeFromNib() { super.awakeFromNib() // Initialization code } }
VC
import UIKit class ViewController: UIViewController { @IBOutlet weak var collectionView: UICollectionView! override func viewDidLoad() { super.viewDidLoad() collectionView.delegate = self collectionView.dataSource = self collectionView.register(SampleCollectionViewCell.self, forCellWithReuseIdentifier: "Cell") } } extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 20 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! SampleCollectionViewCell // ここでクラッシュしてしまいます cell.hogeView.backgroundColor = .black return cell } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。