title: UICollectionView missing some cells
body: <p>I'm trying to make my custom calendar. And the problem is that after applying my custom UICollectionViewFlowLayout some of the cells started to disappear, while first section is looking good, but others are not.</p>
  
  <p><strong>Section 1</strong></p>
  
  <p><a href="https://i.stack.imgur.com/qaIyQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qaIyQ.png" alt="Section 1"></a></p>
  
  <p><strong>Section 2</strong></p>
  
  <p><a href="https://i.stack.imgur.com/MwXHG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MwXHG.png" alt="Section 2"></a></p>
  
  <p>This is a code for my flowLayout class.</p>
  
  <pre><code>class CalendarFlowLayout: UICollectionViewFlowLayout {
  
  override func layoutAttributesForItem(at indexPath: IndexPath) -&gt; UICollectionViewLayoutAttributes? {
      let layoutAttributesForCells = super.layoutAttributesForItem(at: indexPath)?.copy() as! UICollectionViewLayoutAttributes
      return recountedAttributesForCell(layoutAttributesForCells)
  }
  
  override func layoutAttributesForElements(in rect: CGRect) -&gt; [UICollectionViewLayoutAttributes]? {
      return super.layoutAttributesForElements(in: rect)?.map {
          attributes in
          let copiedAttributes = attributes.copy() as! UICollectionViewLayoutAttributes
          return recountedAttributesForCell(copiedAttributes)
      }
  
  }
  
  func recountedAttributesForCell(_ attributes: UICollectionViewLayoutAttributes) -&gt; UICollectionViewLayoutAttributes {
      if let collectionView = self.collectionView {
  
          let sectionOffset = CGFloat(attributes.indexPath.section) * collectionView.frame.height
  
          let itemsPerRow : CGFloat = 7
          let cellSize : CGFloat = collectionView.frame.width / itemsPerRow
          attributes.size = CGSize(width: cellSize, height: cellSize)
  
          let xOffset : CGFloat = CGFloat(attributes.indexPath.item % 7) * cellSize
          var yOffset : CGFloat = CGFloat(attributes.indexPath.item / 7) * cellSize
          yOffset += sectionOffset
  
          attributes.frame = CGRect(x: xOffset, y: yOffset, width: cellSize, height: cellSize)
      }
      return attributes
  }
  }
  </code></pre>