vendredi 10 septembre 2021

How to show two Collectionviews according to "if" conditions in Swift

I have Two collectionviews. 1)newCollectionview 2) oldCollectionview in HomeVC

initially when i add images then i need to show newCollectionview with newArray.count

if i come from ServiceVC to HomeVC then isEdit becomes true and

  • if there are images in oldArray then i need to show oldCollectionview`
  • if oldArray is empty and if i add images then i need to show newCollectionview
  • if images in oldArray and if i add images in HomeVC then i need to show oldCollectionview and newCollectionview

i need to show all the time(initially and isEdit times) added images should show in newCollectionview with newArray.count

only if i send oldArray to HomeVC then only i need to show oldCollectionview with oldArray

code:

with this code initially in HomeVC i am not able to show images in newCollectionview

and in isEdit condition if there are no images in oldArray and if want to add images then also not able to add images in newCollectionview

only if there are images in oldArray then i am able to show in oldCollectionview and add new images in newCollectionview.. only upto oldArray.count

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


if isEdit{

if oldArray.isEmpty == false{

   if collectionView == oldCollectionview{

    return  oldArray.count
     }
}

if newArray.isEmpty == false{
    if collectionView == newCollectionView{
       return  self.newArray.count
     }
}

if oldArray.isEmpty == false && newArray.isEmpty == false{

    if collectionView == oldCollectionview{
     return  oldArray.count
      }
     if collectionView == newCollectionView{
        return  self.newArray.count
      }
}
}
else{

if collectionView == newCollectionView{
   return  self.newArray.count
 }
 }
 return newArray.count
 }




 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

if isEdit{

if oldArray.isEmpty == false{

    if collectionView == oldCollectionview{

        let cell = oldCollectionview.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell

        let img = "\(CommonUrl.bidsAttachment)\( self.oldArray[indexPath.item].image ?? "")"
        cell?.imgView.getImage(withUrl: img, placeHolder: #imageLiteral(resourceName: "home"), imgContentMode: .scaleAspectFill)
    }

}
if newArray.isEmpty == false{
     if collectionView == newCollectionView{

        let cell = newCollectionView.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
         cell?.imgView.image = self.newArray[indexPath.item]

         return cell!
     }

 }

if oldArray.isEmpty == false && newArray.isEmpty == false{

    if collectionView == oldCollectionview{

        let cell = oldCollectionview.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
        let img = "\(CommonUrl.bidsAttachment)\( self.oldArray[indexPath.item].image ?? "")"
        cell?.imgView.getImage(withUrl: img, placeHolder: #imageLiteral(resourceName: "home"), imgContentMode: .scaleAspectFill)
      
           return cell!
    }
    if collectionView == newCollectionView{

       let cell = newCollectionView.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
        cell?.imgView.image = self.newArray[indexPath.item]

        return cell!
    }

}
}
else{
if collectionView == newCollectionView{

   let cell = newCollectionView.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
    cell?.imgView.image = self.newArray[indexPath.item]

    return cell!
}

}
return UICollectionViewCell()

}
}

how to show added images in newCollectionview, please do help.. i got stuck here from long

Aucun commentaire:

Enregistrer un commentaire