ios - 无法在 UItableviewcell 中加载 collectionview

标签 ios swift uitableview

从自定义表格单元格重新加载时,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 包含一个下拉列表,如图所示 enter image description here

最佳答案

首先,执行此操作并检查

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/

相关文章:

ios - 返回不同值的 NSCalendar 组件

ios - 推送通知在被删除之前在队列中停留多长时间?

ios - 如何更改 AVPlayer 中播放音频的速度?

json - 在 Swift 中访问嵌套数据

iphone - UITableView 的 tableHeaderView 高度属性在加载和旋转期间更改为奇怪的值

ios - UITableViewCell 在关闭模态呈现的 ViewController 后不反射(reflect)更改

ios - Xcode - unicode 字符 MD 未出现在模拟器中

swift - 为什么这段代码会生成如此令人困惑的错误消息?

ios - 将特定类型的数据显示到 TableView

ios - CoreData : warning: Unable to load class named 'Task' for entity 'Task' . 找不到类,改用默认的 NSManagedObject