【问题标题】:Reload data Collection View inside Table view Cell (Swift)在表格视图单元(Swift)中重新加载数据集合视图
【发布时间】:2019-07-08 19:14:13
【问题描述】:

我在表格视图单元格内遇到了嵌套集合视图的问题。内容是从在线数据库上传的,需要一段时间才能获取数据。我的问题是如何继续为 Collection View 重新加载数据,直到从在线数据库中获取内容然后显示它。

class DiscoverViewCell: UITableViewCell {
    @IBOutlet weak var categoryLabel: UILabel!
    @IBOutlet weak var _collectionView: UICollectionView!
    @IBAction func seeMoreAction(_ sender: Any) {
    }

}
class MovieCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var moviePicture: UIImageView!
    @IBOutlet weak var movieTitleLabel: UILabel!
    func updateCollectionCell(movie: MovieModel){
        moviePicture.image = movie.poster
        movieTitleLabel.text = movie.name
    }

}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MovieCell", for: indexPath) as? MovieCollectionViewCell else {
        return UICollectionViewCell()
    }

    cell.updateCollectionCell(movie: movieArray[indexPath.item])
    return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "DiscoverCell") as? DiscoverViewCell else {
        return UITableViewCell()
    }

    cell.categoryLabel.text = categories[indexPath.item]
    setUpCell(cell)
    return cell
}

此外,如何根据每个表视图单元格内但与集合视图分离的标签在表视图单元格内显示不同的集合视图内容。

【问题讨论】:

    标签: swift uitableview uicollectionview uicollectionviewcell


    【解决方案1】:

    解决此问题的最佳方法是在用于封装所有在集合视图中呈现的数据。

    因此,如果您有 tableViewCell 的模型,以及嵌套 collectionView 的嵌套模型,我个人会在此 collectionViewModel 中添加一个枚举,用于确定该特定 UICollectionView 的当前状态。因此,例如,如果 UITableView 有许多单元格,并且用户正在快速滚动它们,那么每次 tableViewCell 出列时,状态将用于确定单元格是否应该显示微调器,或者之前检索的数据是否应该呈现(加载与加载)。

    【讨论】:

    • 我设法通过将每个集合视图的标签标记为 indexPath.item 并检查每个标签并显示所需的信息来解决问题。
    • @AndreiEnache 我很高兴听到你解决了它!一定要看看我提到的方式;一个很好的练习,只是为了学习一种不同的方法。
    • 我在这里遇到了类似的问题。任何人都可以在这里分享一些逻辑作为回应?
    • @PoolHallJunkie 你为什么不发布你的代码
    猜你喜欢
    • 2018-07-23
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多