【发布时间】:2017-10-07 14:08:36
【问题描述】:
我有一个 UICollection 视图,它有两个自定义单元格。 UICollectionViewCell 自定义单元格是使用 NIB 构建的。在其中一个 UICollectionViewCell NIB 中,我有一个 UITableView。但是,UITableView 本身具有自定义单元格。所以我的问题是:
如何为 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
}
}
【问题讨论】:
标签: ios swift uitableview uicollectionview nib