Tuesday, January 2, 2024
HomeiOS Developmentios - drag & drop in assortment view and updating indexpath in...

ios – drag & drop in assortment view and updating indexpath in label


I’ve problem the place I’m utilizing two collwctionview, one has information with id, picture and in second assortment view I am appending cell from first collectionview and performing drag and drop. in second assortment view I’ve one label which is displaying variety of appending information in depend as I’m taking indexpath.depend, now the problem is each time I am dragging and dropping cell I get repetition of indexpath in label. what ought to I do?

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection part: Int) -> Int {
        if collectionView == stretchAddedCV{
            return addRoutine.depend
        }
        else{
            return self.arrRoutine.depend
        }
    }
    
    // drag and Drope Mothed
    func collectionView(_ UICollectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        guard destinationIndexPath.merchandise < addRoutine.depend else {
            return
        }
        let temp = self.addRoutine.take away(at: sourceIndexPath.merchandise)
        self.addRoutine.insert(temp, at: destinationIndexPath.merchandise)
        
        self.stretchAddedCV.reloadItems(at: [destinationIndexPath, sourceIndexPath])       
    }
    
    //drag and Drope Longe press
    @objc func handleLongGesture(gesture: UILongPressGestureRecognizer) {
        swap gesture.state {
        case .started:
            guard let selectedIndexPath = self.stretchAddedCV.indexPathForItem(at: gesture.location(in: self.stretchAddedCV)) else {
                break
            }
            self.stretchAddedCV.beginInteractiveMovementForItem(at: selectedIndexPath)
        case .modified:
            self.stretchAddedCV.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!))
        case .ended:
            self.stretchAddedCV.endInteractiveMovement()
        default:
            self.stretchAddedCV.cancelInteractiveMovement()
        }}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments