0

I'm implementing a simple collection view cell, in which data is displaying according to API getters, But in API there is also an integer with the name: "Display Order" in which integer is coming i.e. 1,2,3.. so I need to order my items inside the cell according to to display order

This is my current cell, as the alternative name is coming similarly display order is also coming in API

I have to show display order in categories, subcategories and in items

Appreciated

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as? CollectionViewCell else { return UICollectionViewCell() }
        
        cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1)
        UIView.animate(withDuration: 0.3, animations: {
            cell.layer.transform = CATransform3DMakeScale(1.05,1.05,1)
        },completion: { finished in
            UIView.animate(withDuration: 0.1, animations: {
                cell.layer.transform = CATransform3DMakeScale(1,1,1)
            })
        })
        
        
        switch currentState {
        case 1:
            if L102Language.currentAppleLanguage() == "ar" {
                cell.populate(with: categories[categoryIndex].subCategories[indexPath.row].alternateName, image: categories[categoryIndex].subCategories[indexPath.row].image)
            } else {
                cell.populate(with: categories[categoryIndex].subCategories[indexPath.row].name, image: categories[categoryIndex].subCategories[indexPath.row].image)
            }
            cell.plusBtn.isHidden = true
            cell.minusBtn.isHidden = true
            cell.countLbl.isHidden = true
            cell.liveImage.isHidden = true
        case 2:
            if L102Language.currentAppleLanguage() == "ar" {
                cell.populate(with: categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].alternateName, image: categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].image)
            } else {
                cell.populate(with: categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].name, image: categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].image)
            }
            let OpenItem = categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].IsOpenItem
            let ItemType = categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].itemType
            
            //Constants.MinOpenPrice = categories[categoryIndex].subCategories[subCategoryIndex].items[indexPath.row].MinOpenPrice
            if !OpenItem && ItemType != "Package" {
                cell.plusBtn.isHidden = false
                cell.minusBtn.isHidden = false
                cell.countLbl.isHidden = false
                cell.liveImage.isHidden = true
                count = count+1
                cell.decorate(for: "\(count)", in: self)
            } else {
                cell.plusBtn.isHidden = true
                cell.minusBtn.isHidden = true
                cell.countLbl.isHidden = true
                if ItemType == "Package" {
                    cell.liveImage.image = UIImage(named: "packages")
                } else {
                    cell.liveImage.image = UIImage(named: "livemark")
                }
                cell.liveImage.isHidden = false
                print(count)
            }
        default:
            if L102Language.currentAppleLanguage() == "ar" {
                cell.populate(with: categories[indexPath.row].alternateName, image: categories[indexPath.row].image)
            } else {
                cell.populate(with: categories[indexPath.row].name, image: categories[indexPath.row].image)
            }
            
            
            cell.index = indexPath
            cell.plusBtn.isHidden = true
            cell.minusBtn.isHidden = true
            cell.countLbl.isHidden = true
            cell.liveImage.isHidden = true
            cell.countLbl.text = "\(count)"
            
            
        }
        
        return cell
    }
Amjad
  • 1
  • 2

0 Answers0