【发布时间】:2017-11-21 11:35:43
【问题描述】:
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 //
}
根据我需要显示两个单元格中的任何一个的条件,我有两种类型的自定义单元格(LightViewCell/DimmerLightViewCell)...... 类型
这里我没有返回任何值,忽略该错误.....我需要知道如何实现上述要求..
谢谢:)
【问题讨论】:
-
为什么不按照
indexPath分类? -
@Anurag 我听不懂你...你能解释清楚吗...
-
让我试试...谢谢
标签: ios swift3 uicollectionview uicollectionviewcell