【发布时间】:2018-12-10 00:30:34
【问题描述】:
我正在尝试在 TableViewCell 中设置 CollectionView。我已经阅读了一堆堆问题、tuts 和视频,到目前为止,我的方法似乎是正确的,但我的集合视图仍然没有加载到我的表格视图单元格中。
代码:
import UIKit
class TheaterCell: UITableViewCell {
@IBOutlet var theaterName: UILabel!
@IBOutlet var theaterLocation: UILabel!
@IBOutlet var showtimesCollection: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
showtimesCollection.delegate = self
showtimesCollection.dataSource = self
showtimesCollection.reloadData()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
extension TheaterCell: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = showtimesCollection.dequeueReusableCell(withReuseIdentifier: "timeCell", for: indexPath) as! TimeCell
cell.time.text = "1:00"
return cell
}
}
Tableview 从 ViewController 加载并显示其单元格和元素,但集合视图未在单元格中加载。
【问题讨论】:
-
您的表格视图单元格出现了吗?
-
是的,如问题中所述,表格视图加载并显示单元格。集合视图不会在单元格中加载。
-
显示表格视图的数据源方法
标签: ios swift uitableview uicollectionview