###前提・実現したいこと
あるUIViewControllerを継承した画面があります 「A画面」
ある画面にxibを使ってUIViewを追加します 「B画面」
その「A画面」上にCollectionViewを追加し、CustomCell用のxibを作成します 「C画面」
この状態で「B画面」「C画面」それぞれにカスタムクラスを追加して、
「B画面」上にCollectionViewを追加しましたがうまく表示されません。
何が原因なのでしょうか。
###該当のソースコード
Swift
1//「A画面」で「B画面」のxibを追加、表示する処理 2functionView = UINib(nibName: "PointCard", bundle: Bundle.main).instantiate(withOwner: self, options: nil)[0] as! UIView 3functionView.frame = self.view.frame 4let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate 5delegate.window?.addSubview(functionView)
Swift
1import UIKit 2 3class PointCard: UIView, UICollectionViewDelegate, UICollectionViewDataSource { 4 5 @IBOutlet weak var collectionView: UICollectionView! 6 7 override init(frame: CGRect) { 8 super.init(frame: frame) 9 } 10 11 required init?(coder aDecoder: NSCoder) { 12 super.init(coder: aDecoder) 13 14 let nib = UINib(nibName: "PointCardCell", bundle: nil) 15 collectionView.register(nib, forCellWithReuseIdentifier: "Cell") 16 //↑ここで 「unexpectedly found nil while unwrapping an Optional value」 17 } 18 19 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 20 return 10 21 } 22 23 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 24 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PointCardCell 25 return cell 26 } 27 28}
###試したこと
###補足情報(言語/FW/ツール等のバージョンなど)
・Xcode8.2.1
・Swift3
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。