[英]Table views inside collection view cells?
I am attempting to use a collection view in a view controller for cards. 我正在尝试在卡片的视图控制器中使用集合视图。 When a user taps on a card, it expands. 当用户点击卡片时,卡片会展开。 At all times, I have a tableview in each card, whether it is expanded or not. 无论何时,无论是否展开,我在每张卡中都具有一张表格视图。 I have the data loading in the table views, but only when I tap on a card to expand it or if I scroll collection view cards offscreen and back onscreen. 我在表格视图中加载了数据,但是只有当我点击某个卡片以将其展开时,或者当我在屏幕外和屏幕后滚动收集视图卡片时,才加载数据。 What is a cleaner workflow to doing this that puts tableviews in each collection view cell? 将表视图放在每个集合视图单元格中的清洁工作流程是什么?
This is in my main view controller: 这是在我的主视图控制器中:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "productionBinderCell", for: indexPath) as? ProductionBinderCollectionViewCell
let suck = cell?.detailsTableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? DescriptionTableViewCell
suck?.descriptionText.text = productions[indexPath.row].productionDescription
cell?.detailsTableView.reloadData()
cell?.layer.shouldRasterize = true
cell?.layer.rasterizationScale = UIScreen.main.scale
let title = productions[indexPath.row].productionTitle
let luck = productions[indexPath.row].productionImage
let zuck = UIImage(data:luck!)
cell?.productionTitle.text = title
cell?.productionFeaturedImage.image = zuck
cell?.productionColorTint.tintColor = UIColor.blue
let backbtn = cell?.viewWithTag(1)
backbtn?.isHidden = true
return cell!
}
This is in a subclass of the tableview: 这在tableview的子类中:
override func layoutSubviews() {
super.layoutSubviews()
self.dataSource = self
self.delegate = self
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "productionDescription", for: indexPath) as? DescriptionTableViewCell
return cell!
}
This is in a subclass of the tableview cell I am concerned with. 这是我关注的tableview单元的子类。 It only shows the uilabel text when scrolling offscreen or tapping on the collection view cell: 仅在屏幕外滚动或点击集合视图单元格时,才显示uilabel文本:
class DescriptionTableViewCell: UITableViewCell {
@IBOutlet var descriptionText: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
Maybe I shouldn't be using a tableview at all? 也许我根本不应该使用tableview? Thank you very much to all who help. 非常感谢所有帮助的人。 I am very open to criticism and love learning from my mistakes (a little too often). 我非常乐于接受批评,也喜欢从错误中学习(经常出错)。 :) :)
What you need, first of all, is clear definition of views and cells. 首先,您需要明确定义视图和单元格。
Do you need to embed entire table view within each card? 您是否需要在每张卡中嵌入整个表格视图? There you have your answer. 在那里,您有答案。 You have parent-child relationship between your UICollectionViewCell and UITableView derived classes: 您的UICollectionViewCell和UITableView派生类之间具有父子关系:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.