Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Eliminar fila de la sección

Esta es mi matriz de sección

 var sectionArray = [Sections]()

Así es como calculo cuántas filas en la sección

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return sectionArray[section].items.count }

y este es mi código para eliminar una fila deslizando.

 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == UITableViewCell.EditingStyle.delete { sectionArray[indexPath.section].remove(at: indexPath.row) if sectionArray[indexPath.section].title.count == 0 { sectionArray.remove(at: indexPath.row) } tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.automatic) } } func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let delete = UITableViewRowAction(style: .normal, title: "Delete") { action, index in //self.isEditing = false print("delete button tapped") } delete.backgroundColor = UIColor.red return [delete] }

Teóricamente, esto debería funcionar, pero recibo un error No hay coincidencias exactas en la llamada al subíndice en

 sectionArray[indexPath.section].remove(at: indexPath.row)
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

/// This line sectionArray.remove(at: indexPath.row) /// should be like this sectionArray.remove(at: indexPath.section) /// This line will remove the section from the table tableView.deleteSections(.init(integer: indexPath.section), with: .automatic)

Estás usando la fila para eliminar una sección

Editar

Reemplace todo el código que nos proporcionó con este

 /* func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == UITableViewCell.EditingStyle.delete { sectionArray[indexPath.section].remove(at: indexPath.row) if sectionArray[indexPath.section].title.count == 0 { sectionArray.remove(at: indexPath.row) } tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.automatic) } } func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let delete = UITableViewRowAction(style: .normal, title: "Delete") { action, index in //self.isEditing = false print("delete button tapped") } delete.backgroundColor = UIColor.red return [delete] } */ func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let delete = UITableViewRowAction(style: .normal, title: "Delete") { action, index in //self.isEditing = false sectionArray[indexPath.section].remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.automatic) if sectionArray[indexPath.section].items.isEmpty { sectionArray.remove(at: indexPath.section) tableView.deleteSections(.init(integer: indexPath.section), with: .automatic) } } delete.backgroundColor = UIColor.red return [delete] }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda