ios - 如何填充在其行中嵌入了 collectionView 的 tableView 并按类型或类别组织它们?

标签 ios swift google-cloud-firestore alamofire

<分区>

我有一个事件/ field 管理应用,一个 View 接收 json 格式的事件数据,其中每个事件都有一个类别或类型。如何填充和组织嵌入在 TableView 单元格中的 collectionView 中的事件,其中每个 TableView 单元格都是要显示的类别或类型。 尽可能用 Swift 回答

最佳答案

使用带有类别的 JSON 填充您的 tableview,并在 cellForRowAt 方法中将单个类别传递给 collectionView(您的 tableview 单元类持有 collectionView 属性)使用

重新加载 collectionView
cell.singleCategory = categories[indexPath.row]
cell.collectionView.reloadData()

将您的 collectionView socket 和委托(delegate)放在 tableView Cell 类中,并创建包含单个类别数据的属性,将类别数据传递给该 tableView Cell 类,并在 cellForItemAt 中填充单个类别数据

例子:

class MyTeamTVC: UITableViewCell {

    @IBOutlet weak var collectionView: UICollectionView!
        var singleCategory = [Category]()
override func awakeFromNib() {

        collectionView.register(UINib(nibName: "cell", bundle: nil), forCellWithReuseIdentifier: "cell")

    }
    }

extension MyTeamTVC: UICollectionViewDelegate, UICollectionViewDataSource {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return category.types.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? StatsCVC else {return UICollectionViewCell()}

        cell.nameLabel.text = singleCategory.types[indexPath.row]
        return cell
    }

}

关于ios - 如何填充在其行中嵌入了 collectionView 的 tableView 并按类型或类别组织它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56406367/

相关文章:

ios - Swift 区域监控本地通知触发器

ios - 如何将具有相同属性的一系列动画链接到三个不同的对象上?

IOS:复制文档文件夹中的文件

ios - 使按钮在按下时填充 UITableView

swift - 无论 swift 中小数点后的位数如何,如何显示 2 个小数位?

ios - 如何在 Swift 中的数组中的特定索引处收集和传递数据?

ios - ContainerView childViewControlllers View 框架占据整个屏幕

firebase - 在 setData() 之后刷新 DocumentSnapshot 而无需额外查询

php - 有没有其他方法可以在不推荐 grpc 扩展的情况下使用 Php 配置 Firestore?

arrays - 多个 Firestore 快照相互覆盖