swift - swift部分中TableViewCell中的CollectionVIew
问题描述
我有 7 个部分的 TableViewController,每个部分有 1 行。
在第 7 节需要将 CollectionView 与 UIImageView 放在一起。
我不知道我做错了什么。我的代码如下。用户有 9 张图片,但没有显示。
class NewDetailPhotographerTableViewController: UITableViewController {
// loading data for display in view
}
extension NewDetailPhotographerTableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 7
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let photo = photographer {
switch section {
case 1:
return photo.photoShootingStyle.isEmpty ? 0 : 1
case 2:
return photo.languages.isEmpty ? 0 : 1
case 3:
return photo.equipment.isEmpty ? 0 : 1
case 5:
return photo.biography.isEmpty ? 0 : 1
case 6:
return photo.images.isEmpty ? 0 : 1
default:
return 1
}
}
return 0
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
}
extension NewDetailPhotographerTableViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photographer?.images.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "imagesCollectionCell", for: indexPath) as! NewDetailPhotographerCollectionViewCell
cell.imageView.kf.setImage(with: URL(string: photographer!.images[indexPath.item]))
return cell
}
}
class NewDetailPhotographerTableViewCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
override func prepareForReuse() {
super.prepareForReuse()
self.collectionView.reloadData()
}
}
class NewDetailPhotographerCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
imageView.contentMode = .scaleAspectFill
imageView.layer.masksToBounds = true
}
}
在屏幕截图中可见 6 个部分,因为第 7 个部分是不可见的。
包括故事板屏幕截图。
解决方案
推荐阅读
- c++ - 函数声明中箭头语法的优点
- java - 如何在 Java ee 中的每个按钮单击时创建新对象?
- git - Git 不使用来自 git-credentials-store 文件的凭据
- excel - 为要导出到 txt 的不同列插入另一个过滤器命令
- java - 为什么当多对一是惰性的时,Hibernate 会出现 StackOverflowError?
- flutter - zsh:找不到命令:颤动?
- azure-data-factory - ADF 复制任务字段类型 boolean 为小写
- jenkins - 詹金斯:用分支名称触发另一个工作
- java - 使用 Location API Android 时,服务的用途是什么?
- javascript - 使用星期几返回特定对象