前提・実現したいこと
xibを使ったカスタムビューの作成をしています。
xib内に配置したUICollectionViewに対してストーリーボード上で
UICollectionViewCellを配置したいのですが、cellをドラッグ&ドロップしても
xib上に配置されなくて困っております。
ViewContoroller上にUICollectionViewを配置して
同様にcellを配置するとcellが配置されるのですがxibの場合だと配置されません。
解決方法がわからず手詰まりになってしまったため、ご教示頂けると幸いです。
該当のソースコード
Swift
1import UIKit 2 3class IconSelectionView: UIView { 4 5 @IBOutlet weak var collectionView: UICollectionView!{ 6 didSet{ 7 //self.collectionView.dataSource = self 8 } 9 } 10 11 override init(frame: CGRect) { 12 super.init(frame: frame) 13 self.nibInit() 14 } 15 16 required init?(coder aDecoder: NSCoder) { 17 super.init(coder: aDecoder) 18 self.nibInit() 19 } 20 21 private func nibInit() { 22 guard let view = UINib(nibName: "IconSelectionView", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else { 23 return 24 } 25 26 view.frame = self.bounds 27 self.addSubview(view) 28 } 29} 30 31extension IconSelectionView:UICollectionViewDataSource { 32 33 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 34 35 return 3 36 } 37 38 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 39 40 let cell = UICollectionViewCell() 41 cell.contentView.backgroundColor = UIColor.green 42 return cell 43 } 44}
試したこと
UICollectionViewの再配置
補足情報(FW/ツールのバージョンなど)
作成したカスタムビュー自体の表示は出来ています
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/04 13:47