Collectionview переходит к условию if, но не вызывается условием else в Swift

#swift #if-statement #uicollectionview #cell

Вопрос:

Я использую два вида коллекций и вызываю их в соответствии с условиями

Изначально я хочу показать newCollectionview с изображениями newArray.

код для просмотра коллекций: с этим кодом условие IsEdit работает идеально.

Но изначально, когда я загружаю изображения из сборщика, то в cellForItemAt другом состоянии они не вызываются, и добавленные изображения в newArray также не отображаются в newCollectionView.

но когда я прихожу из IsEdit, if collectionView == newCollectionView это работает, но если это не из IsEdit, то он не звонит, почему?

Вот numberOfItemsInSection это тоже призвание.. но изображения не отображаются в строке

 struct ImagesModel{

public var image : String?
init(image: String?) {
    self.image = image
}
}


import UIKit

class BidPlaceVC: UIViewController, UITextViewDelegate {

var oldArray = [ImagesModel]()
var newArray = [UIImage]()

override func viewDidLoad() {
    super.viewDidLoad()
    
    let layout = UICollectionViewFlowLayout()
    
    layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    
    layout.scrollDirection = .horizontal
    let width = UIScreen.main.bounds.width/4.1
    let height = width*1.1
    
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 5
    layout.itemSize = CGSize(width: width, height: 100)

    self.newCollectionView.collectionViewLayout = layout
    
    self.oldCollectionnview.collectionViewLayout = layout

    newCollectionView.reloadData()
    oldCollectionnview.reloadData()
 }
 
}

extension BidPlaceVC : UICollectionViewDelegate,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    
    if isEdit {// here all conditions working
        if newArray.isEmpty{

        if collectionView == oldCollectionnview{

        return  oldArray.count
        }
        }
        else{
            if collectionView == oldCollectionnview{

            return  oldArray.count
            }
            if collectionView == newCollectionView{

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

        return  self.newArray.count// is calling
        }
    }
    return newArray.count
 }

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

    if isEdit{
        
        if newArray.isEmpty{
            if collectionView == oldCollectionnview{

              let cell = oldCollectionnview.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!
            }

        }
        else{
            
            if collectionView == oldCollectionnview{

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

               let img = "(CommonUrl.bidsAttachment)( self.oldArray[indexPath.item].image ?? "")"
               print("(img)")
               cell?.imgView.getImage(withUrl: img, placeHolder: #imageLiteral(resourceName: "home"), imgContentMode: .scaleAspectFill)
                   return cell!
            }
             // if i come from isEdit then its calling.. and images showing in newCollectionView
            if collectionView == newCollectionView{

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

                cell?.imgView.image = self.newArray[indexPath.item]
              
                return cell!
                
            }
            
        }
      
        }
        //******* here is not being called ******
       else{
        
        if collectionView == newCollectionView{

           let cell = newCollectionView.dequeueReusableCell(withReuseIdentifier: "FilesCollectionCell", for: indexPath) as? FilesCollectionCell
            print("first time (self.newArray)")
            cell?.imgView.image = self.newArray[indexPath.item]
            
            return cell!
        }
    }
    return UICollectionViewCell()

}

}


extension BidPlaceVC : EasyImagePickerDelegate{

func didSelect(image: UIImage?, video: URL?, fileName: String?) {
    if let img = image{
        self.imageProfile = img
    
        self.newArray.append(img)
        print("added images (newArray)")
        self.newCollectionView.reloadData()
    }
}
}
 

пожалуйста, помогите решить эту проблему