Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Cómo explicar "completionHandler (verdadero)"

Estoy siguiendo un tutorial en línea sobre una acción de deslizamiento de TableView Cell. Puedo explicarme a mí mismo cada línea, excepto completionHandler(true)

Este es el fragmento de código

 override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, sourceView, completionHandler) in //Delete self.restaurantNames.remove(at: indexPath.row) self.restaurantLocations.remove(at: indexPath.row) self.restaurantTypes.remove(at: indexPath.row) self.restaurantIsVisited.remove(at: indexPath.row) self.restaurantImages.remove(at: indexPath.row) self.tableView.deleteRows(at: [indexPath], with: .fade) // Call completion handler to dismiss the action button completionHandler(true) } let shareAction = UIContextualAction(style: .normal, title: "Share") { (action, sourceView, completionHandler) in let defaultText = "Just checking in at" + self.restaurantNames[indexPath.row] let activityController = UIActivityViewController(activityItems: [defaultText], applicationActivities: nil) self.present(activityController, animated: true, completion: nil) // Call completion handler to dismiss the action button completionHandler(true) } let swipeConfiguration = UISwipeActionsConfiguration(actions: [deleteAction, shareAction]) return swipeConfiguration }

no entiendo muy bien que significa esto? Gracias por adelantado

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Todas las respuestas existentes simplemente pegan la documentación de Apple que responde precisamente a nada. Dice cuándo se debe llamar, pero nada sobre lo que le hace a la interfaz de usuario.

Por lo que puedo decir, llamar a completeHandler con cualquiera de los valores colapsará los botones. Puede ver esto en acción llamando al controlador de finalización en un bloque dispatch_after con un retraso. Especificar verdadero o falso no hace ninguna diferencia en mis pruebas.

Tengo la sensación de que me estoy perdiendo algo, pero la documentación de Apple es opaca aquí.

over 4 years ago · Santiago Trujillo Report

0

Explicación: llama al controlador de finalización con verdadero para indicar que realizó la acción o con falso si no pudo hacerlo por algún motivo.

Verifique el trabajo del código de demostración a continuación:

 func contextualToggleFlagAction(forRowAtIndexPath indexPath: IndexPath) -> UIContextualAction { var email = data[indexPath.row] let action = UIContextualAction(style: .normal, title: "Flag") { (contextAction: UIContextualAction, sourceView: UIView, completionHandler: (Bool) -> Void) in if email.toggleFlaggedFlag() { self.data[indexPath.row] = email self.tableView.reloadRows(at: [indexPath], with: .none) completionHandler(true) // your task is successfully done. } else { completionHandler(false) // With some reason you unable to perform task so now you returning false. } } action.image = UIImage(named: "flag") action.backgroundColor = email.isFlagged ? UIColor.gray : UIColor.orange return action }
over 4 years ago · Santiago Trujillo Report

0

El tercer parámetro del controlador UIContextualAction es un cierre que le dice a UIContextualAction si realizó o no la acción. Al llamar a completionHanlder(true) , notifica a UIContextualAction que realizó la acción solicitada. Si, por ejemplo, hubo un error en su controlador que le impidió realizar la acción deseada, puede notificar al controlador llamando a completionHandler(false) .

Documentación: https://developer.apple.com/documentation/uikit/uicontextualaction/handler

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!