Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
UIDropInteractionDelegate performDrop not called?

I am trying to build a simple test app to learn Drag and Drop APIs. For this question I am focusing only on the Drop scenario. I have a blank View Controller, with the safari app open (multitasking) I then try to drag an image from google onto the View Controller's view.

I can drag the image from safari to my app's View Controller, but when I let go, this call below is never called:

func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession)

This is my code:

class EditTestVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        view.addInteraction(UIDropInteraction(delegate: self))
    }

}

extension EditTestVC:UIDropInteractionDelegate {

    func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool { // 1
        print("canHandle session: \(session)")
        return true
//        return session.canLoadObjects(ofClass: UIImage.self)
    }

    func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal { // 2
        print("sessionDidUpdate session: \(session)")
        return UIDropProposal(operation: .copy)
    }

    func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
        print("performDrop session: \(session)")
    }


}

The top two methods are called, this one:

func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool

and this one:

func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal

So, I am trying to figure out why this one:

func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession)

is never called.

Any suggestion?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

In my case it was a programming error where I've written the following:

func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {

    return UIDropProposal(operation: .move)
}

But you cannot always use move! Only if session.allowsMoveOperation is true!

From the move documentation:

You may use this operation only if the drop session's allowsMoveOperation property is true; otherwise, it's treated as a UIDropOperation.cancel operation. [...]

From the cancel documentation:

If the user attempts a drop activity, the drag operation is canceled and the dropInteraction(_:performDrop:) delegate method is not called.

over 4 years ago · Santiago Trujillo Relatório

0

first of all, as of iOS 15 dragSessionAllowsMoveOperation is true by default

Discussion If you don't implement this method, the default return value is YES.

In my case func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator)

was not called because I had set a breakpoint inside

func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?)

This breakpoint was preventing, for same reason, the other delegate method to be triggered. As soon as I removed them everything worked fine.

I hope this help others as it was driving me crazy.

over 4 years ago · Santiago Trujillo Relatório

0

I just tested your code and all methods are getting called. It must be a glitch.

Troubleshooting steps:

Delete app -> Restart the simulator -> Clean build folder -> Rebuild -> Run. You can also try running in different simulator first to save time.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda