func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let dev = devices[indexPath.item]
if dev.cuid == "3011"{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "LightViewCell", for: indexPath) as! LightViewCell
let visibility = self.getStatusFor(nodeID: dev.node_id!, endpoint: dev.end_point!, devicename: dev.device_name!)
if visibility.contains("0"){
cell.LigntIMG.image = #imageLiteral(resourceName: "bulb-off")
cell.LightName.text = dev.device_name
cell.status = 0
cell.index = indexPath
cell.controlCMDs = getControlCMDS(nodeID: dev.node_id!, endpoint: dev.end_point!)
cells.append(cell)
}else{
cell.LigntIMG.image = UIImage(named: dev.menu_id!)
cell.LightName.text = dev.device_name
cell.status = 1
cell.index = indexPath
cell.controlCMDs = getControlCMDS(nodeID: dev.node_id!, endpoint: dev.end_point!)
cells.append(cell)
}
return cell
}
else if dev.cuid == "3006"{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DimmerLightViewCell", for: indexPath) as! DimmerLightViewCell
return cell
}
return //
}
我有兩種類型的基於i需要顯示兩個單元中的任一個的條件定製單元(LightViewCell/DimmerLightViewCell)的...... 類型如何在單個集合中實現不同的集合視圖單元格類型View?
我在這裏沒有返回任何價值,忽略錯誤.....我需要知道如何實現上述要求..
謝謝:)
你爲什麼不按'indexPath'分類? –
@Anurag我不能讓你...你能解釋清楚嗎... –
讓我試試看...謝謝 –