swift - 在表格 View 单元格中重新加载数据收集 View (Swift)

标签 swift uitableview uicollectionview uicollectionviewcell

我在表格 View 单元格中遇到嵌套 Collection View 的问题。内容是从在线数据库上传的,需要一段时间才能获取数据。我的问题是如何继续为 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
}

此外,如何根据每个表格 View 单元格内但与 Collection View 分开的标签在表格 View 单元格内显示不同的 Collection View 内容。 Storyboard here

最佳答案

解决此问题的最佳方法是在用于封装所有数据的模型中包含用于确定数据是否已被检索或正在从外部源检索数据的所有逻辑 Collection View 中显示的数据。

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

关于swift - 在表格 View 单元格中重新加载数据收集 View (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54695852/

相关文章:

ios - UICollectionViewDataSource 无法执行 "fix it",在 Xcode 9.3.1 中为 "Candidate is not a function"

ios - Google map 实用程序 IOS Pod 错误

swift - 在用户购买之前锁定游戏的特定部分

swift - 在 Foundation 中找不到 FileManager Swift 类,它在哪里?

ios - 取消选择 RowAtIndexPath 问题

iphone - UITableView 使用 PhoneGap 的外观和感觉

objective-c - 在我按返回键并选择另一个选项后,表格没有刷新。始终与第一个选择相同的表

swift - UICollectionView 单元格之间的奇怪间隙(Swift)

ios - 在同一 View Controller 中对多个 Collection View 或 TableView 实现 3D 触摸

swift - 让 tvOS 游戏 handle 按钮每次按下按钮时仅发送一次消息