0

After updating from swift 4 to swift 5, my UICollectionView is disappearing while scrolling (ONLY horizontal view) because in the gif file there's another UICollectionView but it's vertical, I didn't face this problem in swift 4, I searched stack overflow and I saw a lot of answer but it didn't helped me ,

this is a gif. file show the process

this is my heightForRowAt function

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    switch indexPath.section {
    case 0:
        return UITableView.automaticDimension
        
    case 1:
        return 200
    case 2:
        return UITableView.automaticDimension
        
    case 3:
        if (self.topAlbumsArray.isEmpty){
            return 300.0
        }else{
            
            return 120.0
        }
        
        
    default:
        return 280
    }
}

this is the collectionView function

        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

          return CGSize(width: 150, height: 200)

      }
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
          return 8
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
          return 8
      }
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
          return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
      }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Joseph
  • 53
  • 4
  • Have you tried any of the solutions in https://stackoverflow.com/questions/13360975/uicollectionviews-cell-disappearing – Deepa Bhat Jan 31 '22 at 03:16
  • all of them nothing change @DeepaBhat – Joseph Jan 31 '22 at 15:45
  • Looks like giving a proper height to collectionview should work. Since the row height for tableview cell is dynamic and even collection view doesnt have a height, is causing the problem. Please add a height constraint greater than or equal to, for collection view. – Deepa Bhat Feb 02 '22 at 04:28
  • where. should I give the height? @DeepaBhat – Joseph Feb 02 '22 at 10:26

0 Answers0