在表格视图单元格内重新加载数据收集视图(快速)

时间:2019-02-14 17:19:59

标签: swift uitableview uicollectionview uicollectionviewcell

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

DiscoverViewCell类:UITableViewCell {

@IBOutlet weak var categoryLabel: UILabel!

@IBOutlet weak var _collectionView: UICollectionView!

@IBAction func seeMoreAction(_ sender: Any) {

}

}

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
}

重写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

1 个答案:

答案 0 :(得分:0)

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

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