[英]How to load a UITable with custom cell inside a UICollectionViewCell that is already a NIB
I have a UICollection view that has two custom cells. 我有一个具有两个自定义单元格的UICollection视图。 The UICollectionViewCell custom cells are built using NIB's.
UICollectionViewCell自定义单元格是使用NIB构建的。 Inside one of the UICollectionViewCell NIB's, I have a UITableView.
在UICollectionViewCell NIB之一中,我有一个UITableView。 However, the UITableView itself has custom cells.
但是,UITableView本身具有自定义单元格。 So my question is:
所以我的问题是:
How do I load a custom cell for the UITableView instead a UICollectionViewCell NIB? 如何为UITableView而不是UICollectionViewCell NIB加载自定义单元格?
import UIKit
class HeaderFooterCollectionViewCell: UICollectionViewCell {
//Tableview
@IBOutlet weak var tableView: UITableView!
//Buttons
@IBOutlet weak var resetButton: UIButton!
@IBOutlet weak var periodButton: UIButton!
@IBOutlet weak var undoButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
// Register cell classes
tableView.register(UINib(nibName: "ShotInformationTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
}
}
extension HeaderFooterCollectionViewCell: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ShotInformationTableViewCell
return cell
}
}
let cell = Bundle.main.loadNibNamed("XIB_File_Name", owner: self, options: nil)?.first as! XIB_Class_Name
在几乎所有情况下, XIB_File_Name == XIB_Class_Name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.