评级值显示错误在集合视图中

时间:2017-11-20 09:31:35

标签: ios swift

我正在开发我的电子商务应用程序中的第三方宇宙视图。我已经完成了对Cosmos View的显示评级值但是当我滚动Collectionview时我有问题,滚动时间显示评级值会改变。我不明白为什么当我滚动收集视图时,评级值已更改。

有人帮助我吗?

3 个答案:

答案 0 :(得分:0)

  • 仔细检查您在每个单元格的cellForItemAtIndexPath中传递正确的值。问题似乎是if / else tableview可重用的单元格。
  • 检查每个if else条件并始终分配正确的值。

你可以分享你的" cellForItemAtIndexPath"代码,所以我们可以帮助你。

答案 1 :(得分:0)

我的cellForRow方法

让cellHomeProductCell:CltnHomeProductCell = collectionView.dequeueReusableCell(withReuseIdentifier:“CltHomeProductCell”,for:indexPath)as! CltnHomeProductCell

 cellHomeProductCell.setUpBestSellerData(arrModelDataBestSeller: arrBestSellerData)

        let dict = arrBestSellerData[indexPath.row] as! [String:AnyObject]

        // Rating Value Set
        let rate = PIService.getStringFromDict(dict: dict, key: "avg_rating")
        print(rate)

        let value = Double(rate)
        print(value)

        if value != nil
        {
            cellHomeProductCell.ratingView.rating = value!
        }

答案 2 :(得分:0)

cellHomeProductCell.setUpBestSellerData(arrModelDataBestSeller:arrBestSellerData)

    let dict = arrBestSellerData[indexPath.row] as! [String:AnyObject]

    // Rating Value Set
    let rate = PIService.getStringFromDict(dict: dict, key: "avg_rating")
    print(rate)

    let value = Double(rate)
    print(value)

    if value != nil
    {
        cellHomeProductCell.ratingView.rating = value!
    }else{
        print("Found nil value")
        cellHomeProductCell.ratingView.rating = 0.0
    }