从自定义表格单元格重新加载时,Collectionview 重新加载不起作用。
我在一个 collectionview 单元格中放了一个下拉菜单。这个下拉菜单也不起作用。
代码如下:
class HotelAvailableRoomsTVCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
//MARK: Life cycle
override func awakeFromNib() {
super.awakeFromNib()
let nib = UINib.init(nibName: "AvailableRoomCVCell", bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: "AvailableRoomCVCell")
collectionView.delegate = self
collectionView.dataSource = self
// Initialization code
}
func initCellWithData(roomJSON:JSON,indexPath:IndexPath,isSingle:Bool) {
DispatchQueue.main.async {
self.collectionView.reloadData()
}
}
}
在 View Controller 中:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HotelAvailableRoomsTVCell", for: indexPath) as! HotelAvailableRoomsTVCell
cell.delegate = self
cell.initCellWithData(roomJSON: (json)!, indexPath: indexPath as IndexPath, isSingle: true)
return cell;
}
屏幕是: 我使用了一个带有动态单元格数的 TableView 作为 Collection View 。此 Collection View 包含一个下拉列表,如图所示
最佳答案
首先,执行此操作并检查
class HotelAvailableRoomsTVCell: UITableViewCell, UICollectionViewDelegate,UICollectionViewDataSource
你也可以这样做,(我已经完成了它的工作),
通过在 HotelAvailableRoomsTVCell
中创建 var 来传递数据。
var collectionData : [String : Any] = []
在cellForRow
cell.collectionData = data
关于ios - 无法在 UItableviewcell 中加载 collectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48278410/