title: Why my collection view disappear when updating the stepper value?
body: <p>here is my simplified code in my view controller</p>
  
  <pre><code> class WishListVC: UIViewController {
  
          @IBOutlet weak var wishListCollectionView: UICollectionView!
  
          private var products = [Product]()
          private var selectedProduct : Product?
  
          override func viewDidLoad() {
              super.viewDidLoad()
  
          }
  
  
  
      //MARK: - cell Delegate
    extension WishListVC : ListProductCellDelegate {
  
       func addToCartButtonDidTapped(at selectedIndexPath: IndexPath, collectionView: UICollectionView) {
  
          guard let userOrder = userOrder else {return}
          let selectedProduct = products[selectedIndexPath.item]
  
          Order.addProductToOrderRealmDatabase(userOrder: userOrder, selectedProduct: selectedProduct)
          wishListCollectionView.reloadData()
          updateBadgeOnCartTabBar()
  
  
      }
  
          func stepperButtonDidTapped(at selectedIndexPath: IndexPath, stepperValue: Int, collectionView: UICollectionView) {
  
              guard let userOrder = userOrder else {return}
              let selectedProduct = products[selectedIndexPath.item]
  
              if stepperValue &gt; 0 {
                  Product.changeProductQuantityInRealmDatabase(selectedProduct: selectedProduct, quantity: stepperValue)
              } else {
                  Order.removeProductFromOrderRealmDatabase(userOrder: userOrder, selectedProduct: selectedProduct)
                  Product.changeProductQuantityInRealmDatabase(selectedProduct: selectedProduct, quantity: 0)
              }
  
              wishListCollectionView.reloadData()
  
              updateBadgeOnCartTabBar()
  
          }
  
  
      }
  
      //MARK: - Collection View Data Source 
      extension WishListVC : UICollectionViewDataSource, UICollectionViewDelegate {
  
          func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
              return products.count
          }
  
          func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
              guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: WishListStoryboardData.CollectionViewIdentifiers.productSliderCell.rawValue, for: indexPath) as? ListProductCell else { return UICollectionViewCell()}
  
  
              cell.productData = products[indexPath.item]
              cell.delegate = self
              cell.collectionView = wishListCollectionView
  
  
  
              return cell
          }
  
      }
  </code></pre>
  
  <p>and here is the code for my collection view cell:</p>
  
  <pre><code>protocol ListProductCellDelegate {
      func addToCartButtonDidTapped(at selectedIndexPath: IndexPath, collectionView : UICollectionView)
      func stepperButtonDidTapped( at selectedIndexPath: IndexPath, stepperValue: Int, collectionView : UICollectionView)
  }
  
  class ListProductCell: UICollectionViewCell {
  
  @IBOutlet weak var productImageViewAspectRatio: NSLayoutConstraint!
  
      @IBOutlet weak var addToCartButton: UIButton!
      @IBOutlet weak var stepper: GMStepper!
  
      var collectionView : UICollectionView?
      var delegate: ListProductCellDelegate?
  
      var productData : Product? {
          didSet {
              updateUI()
          }
      }
  
      @IBAction func addToCartButtonDidPressed(_ sender: UIButton) {
  
          guard let collectionView = collectionView else {return}
          guard let selectedIndexPath = collectionView.indexPathForView(view: sender) else {return}
          self.delegate?.addToCartButtonDidTapped(at: selectedIndexPath, collectionView: collectionView)
      }
  
      @IBAction func stepperDidTapped(_ sender: GMStepper) {
          guard let collectionView = self.collectionView else {return}
          guard let selectedIndexPath = collectionView.indexPathForView(view: sender) else {return}
          self.delegate?.stepperButtonDidTapped(at: selectedIndexPath, stepperValue: Int(sender.value), collectionView: collectionView)
      }
  
      private func updateUI() {
          guard let product = productData else {return}
  
          stepper.value = Double(product.quantity)
  
          setLikeButton(product: product)
          setCartAndStepperButton()
      }
  
  
      private func setCartAndStepperButton() {
  
          guard let selectedProduct = productData else {return}
  
          func showStepperButton(status: Bool) {
              // to decide whether to show stepper or add to cart button.
  
              stepper.isHidden = !status
              stepper.isEnabled = status
  
              addToCartButton.isHidden = status
              addToCartButton.isEnabled = !status
  
          }
  
          if selectedProduct.quantity == 0 {
              showStepperButton(status: false)
          } else {
              showStepperButton(status: true)
          }
  
  
      }
  
  
  }
  </code></pre>
  
  <p>I don't understand why after I tap the stepper for the first time after the 'Add To Cart' disappear, the collection view will disappear.</p>
  
  <p>I don't have <code>collectionView.isHidden</code> in my entire code, but I don't know why my collection view disappear like the file .gif below</p>
  
  <p><a href="http://g.recordit.co/NAEc36MbrM.gif" rel="nofollow noreferrer">http://g.recordit.co/NAEc36MbrM.gif</a></p>
  
  <p>but if the stepper is already show with some stepper value more than 1, then it will make my collection view dissapear like the gif below</p>
  
  <p><a href="http://recordit.co/SLdqf1ztFZ.gif" rel="nofollow noreferrer">http://recordit.co/SLdqf1ztFZ.gif</a></p>
  
  <p>the minimum stepper value is set to be 1.</p>
  
  <p>If I change the collection view reload data <code>wishListCollectionView.reloadData()</code> in the <code>stepperButtonDidTapped</code> method above to be just reload data in certain cell only using <code>wishListCollectionView.reloadItems(at: [selectedIndexPath])</code> the problem will be solved, but the stepper value seems it will be updated little slower, and it looks laggy.</p>
  
  <p>I don't know how to trace the last line that will be executed so it makes my collection view disappears.</p>
  
  <p>and if I reload the data in the main thread using:</p>
  
  <pre><code>DispatchQueue.main.async {
              self.wishListCollectionView.reloadData()
          }
  </code></pre>
  
  <p>it won't make the collection view disappear, but If I edit the cell index 4 it will affect the cell index 1 like gif here: <a href="http://g.recordit.co/6802BJDdtx.gif" rel="nofollow noreferrer">http://g.recordit.co/6802BJDdtx.gif</a></p>
  
  <p>I change the number in the fifth cell but it will automatically change the second cell.</p>