<分区>
我有一个事件/ field 管理应用,一个 View 接收 json 格式的事件数据,其中每个事件都有一个类别或类型。如何填充和组织嵌入在 TableView 单元格中的 collectionView 中的事件,其中每个 TableView 单元格都是要显示的类别或类型。 尽可能用 Swift 回答
<分区>
我有一个事件/ field 管理应用,一个 View 接收 json 格式的事件数据,其中每个事件都有一个类别或类型。如何填充和组织嵌入在 TableView 单元格中的 collectionView 中的事件,其中每个 TableView 单元格都是要显示的类别或类型。 尽可能用 Swift 回答
最佳答案
使用带有类别的 JSON 填充您的 tableview,并在 cellForRowAt 方法中将单个类别传递给 collectionView(您的 tableview 单元类持有 collectionView 属性)使用
重新加载 collectionViewcell.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/