【发布时间】:2017-12-29 23:59:04
【问题描述】:
问题
我正在尝试在卡片视图控制器中使用集合视图。当用户点击卡片时,它会展开。在任何时候,我在每张卡片中都有一个 tableview,无论它是否扩展。我在表格视图中加载了数据,但只有当我点击卡片以展开它或者我将集合视图卡片滚动到屏幕外并返回屏幕时。将表格视图放在每个集合视图单元格中的更简洁的工作流程是什么?
这是在我的主视图控制器中:
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!
}
这是在 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!
}
这是我关注的 tableview 单元格的子类。它仅在屏幕外滚动或点击集合视图单元格时显示 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
}
}
也许我根本不应该使用 tableview?非常感谢所有提供帮助的人。我非常乐于接受批评,喜欢从错误中吸取教训(有点太频繁了)。 :)
【问题讨论】:
-
集合视图是水平的吗???
-
是的,它水平滚动
标签: ios swift uitableview uicollectionview uicollectionviewcell