Ios 从集合视图创建子视图控制器
我正在尝试为我的集合视图创建子视图,但每当我运行应用程序并从集合视图中选择单元格时,都不会显示任何内容。如何解决此问题,以便在选定单元格后显示tableView 这是我的collectionView的代码Ios 从集合视图创建子视图控制器,ios,swift,xcode,uicollectionview,parent-child,Ios,Swift,Xcode,Uicollectionview,Parent Child,我正在尝试为我的集合视图创建子视图,但每当我运行应用程序并从集合视图中选择单元格时,都不会显示任何内容。如何解决此问题,以便在选定单元格后显示tableView 这是我的collectionView的代码 import UIKit class ContentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { let imageArray = [UIImage(named
import UIKit
class ContentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
let imageArray = [UIImage(named: "image 1"), UIImage(named: "image 2"), UIImage(named: "image 3")]
override func viewDidLoad() {
super.viewDidLoad()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
cell.mapIconImage.image = imageArray[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let child = MapItemsViewController()
addChild(child)
view.addSubview(child.view)
child.didMove(toParent: self)
}
class CustomCell: UICollectionViewCell {
@IBOutlet weak var mapIconImage: UIImageView!
}
您正在尝试在单击集合视图单元格时显示tableview?是的,我正在尝试这样做