ContainerViewの中にCollectionViewを置いても内容が表示されません....。解決方法を教えてください><。
普通のViewControllerに置いている場合は表示され、
またContainerVIewに画像だけおくのであれば表示されるのですが...。
前述したContainerViewの中にCollectionViewを置いても内容が表示されません....。解決方法待ってます!
swift
1import UIKit 2 3class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 4 5 let photos = ["mana1", "mana2","mana3"] 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view, typically from a nib. 10 } 11 12 func numberOfSections(in collectionView: UICollectionView) -> Int { 13 // #warning Incomplete implementation, return the number of sections 14 return 1 15 } 16 17 18 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 19 // #warning Incomplete implementation, return the number of items 20 return 3 21 } 22 23 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 24 // Cell はストーリーボードで設定したセルのID 25 let testCell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) 26 27 // Tag番号を使ってImageViewのインスタンス生成 28 let imageView = testCell.contentView.viewWithTag(1) as! UIImageView 29 // 画像配列の番号で指定された要素の名前の画像をUIImageとする 30 let cellImage = UIImage(named: photos[(indexPath as IndexPath).row]) 31 // UIImageをUIImageViewのimageとして設定 32 imageView.image = cellImage 33 34 return testCell 35 } 36 37}
回答2件
あなたの回答
tips
プレビュー