swiftcollectionviewswift-block

Update label of collection view Cell when I perform some action on the Previous cell and move to the next cell


I have implemented the collection view with two custom cell

When I press a button on the first cell then scrolling to the second cell in the collectionviiew but I need to change the value of label which is inside the second cell

Let say I have a textfield in the first cell and a label in the second cell.

When I enter the value in the first cell and click next then I am calling a block from the first cell and scrolling the collectioview to second cell and wants to set the value of label which I have entered in the textfield of first cell.

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    switch indexPath.item {
    case 0:
        let secondCell = collectionView.dequeueReusableCell(withReuseIdentifier: "secondCell", for: indexPath) as! SecondCell
        secondCell.packages = FindJobVC.subcripDetail.package
        secondCell.moveToNextStep = { textFieldValue in 

    // here I want to change the label text of  CheckoutCell 

            self.cvFindJob.scrollToItem(at: IndexPath(item: indexPath.item + 1, section: 0), at: .centeredHorizontally, animated: true)
            self.cvFindJob.reloadItems(at: [IndexPath(item: indexPath.item + 1, section: 0)])
        }
        return secondCell
   case 1:
        let checkoutCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CheckoutCell", for: indexPath) as! CheckoutCell
        checkoutCell.makePayment = {
            self.makePayment()
        }
        checkoutCell.moveToPreviousStep = {
            self.cvFindJob.scrollToItem(at: IndexPath(item: indexPath.item - 1, section: 0), at: .centeredHorizontally, animated: true)
        }
        return checkoutCell
    }
}

Solution

  • You just need to uncheck the "Prefetching Enabled" and you are ready to go.

    Good luck