在表视图Cell(Swift)中重新加载数据集合视图

问题描述 投票:0回答:1

我在Table View Cell中遇到了嵌套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
}

此外,如何在表视图单元格内显示不同的集合视图内容,具体取决于每个表视图单元格内但与集合视图分离的标签.Storyboard here

swift uitableview uicollectionview uicollectionviewcell
1个回答
0
投票

解决此问题的最佳方法是在用于封装所有数据的模型中包含用于确定数据是否已被检索的所有逻辑,或者是否正在从外部源检索数据的过程中在集合视图中呈现。

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

© www.soinside.com 2019 - 2024. All rights reserved.