可配置的ucollectionview保持重复从json加载的数据

时间:2018-02-28 00:26:24

标签: ios swift uicollectionview swift4 uistepper

我正在尝试根据设置容器视图中的步进器值配置一个uicollectionview,但是当它应该隐藏或显示uicollectionview的列或行时,它会反复显示从json接收到的uicollectionviewcell中的相同第一个数据基于设置容器视图上的步进器值。

  func updatemimicrowcolumns() -> Void {

    // subtract the number of colums (for the 1-pt spacing between cells), and divide by number of columns
    let w = (mimic1colview.frame.size.width - CGFloat((columncountcg - 1))) / CGFloat(columncountcg)

    // subtract the number of rows (for the 1-pt spacing between rows), and divide by number of rows
    let h = (mimic1colview.frame.size.height - CGFloat((rowcountcg - 1))) / CGFloat(rowcountcg)

    // reload the collection view
    mimic1colview.reloadData()

}




func numberOfSections(in collectionView: UICollectionView) -> Int {
    return rowcountcg

}



func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return columncountcg

    }


func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = mimic1colview.dequeueReusableCell(withReuseIdentifier: "colcell", for: indexPath) as! MimicCell1

    let getDesc = desc[safe: indexPath.row]
    let getVal = valu[safe: indexPath.row]
    let getNum = state[safe: indexPath.row]
    let devName = dev[safe: indexPath.row]

    if getNum == "2"
    {
        statmsg = "Normal"
        cell.devdes1.text = getDesc
        cell.devvalue1.text = getVal
        cell.devstate1.text = statmsg
        cell.devname1.text = devName
        cell.devstate1.textColor = UIColor.green

    }
    else if getNum == "3"
    {
        statmsg = "Alarm"
        cell.devdes1.text = getDesc
        cell.devvalue1.text = getVal
        cell.devstate1.text = statmsg
        cell.devname1.text = devName
        cell.devstate1.textColor = UIColor.red


    }


       return cell

}

在getnum中添加了打印值:

  

[“2”,“2”,“3”,“2”,“3”,“2”,“3”,“3”,“2”,“2”] [“2”,“ 2“,”3“,   “2”,“3”,“2”,“3”,“3”,“2”,“2”,“2”,[“2”,“2”,“3”,“2”,“ 3“,”2“,   “3”,“3”,“2”,“2”,“2”,“3”] [“2”,“2”,“3”,“2”,“3”,“2”,“ 3“,”3“,   “2”,“2”,“2”,“3”,“2”] [“2”,“2”,“3”,“2”,“3”,“2”,“3”,“ 3“,”2“,   “2”,“2”,“3”,“2”,“3”] [“2”,“2”,“3”,“2”,“3”,“2”,“3”,“ 3“,”2“,   “2”,“2”,“3”,“2”,“3”,“2”] [“2”,“2”,“3”,“2”,“3”,“2”,“ 3“,”3“,   “2”,“2”,“2”,“3”,“2”,“3”,“2”,“3”] [“2”,“2”,“3”,“2”,“ 3“,”2“,   “3”,“3”,“2”,“2”,“2”,“3”,“2”,“3”,“2”,“3”,“3”,[“2”,“ 2“,”3“,   “2”,“3”,“2”,“3”,“3”,“2”,“2”,“2”,“3”,“2”,“3”,“2”,“3 “,”3“,   “2”]

0 个答案:

没有答案