Donc j'essaye de supprimer des données d'un tableView
, qu'il effacera la cellule à la rangée, mais il ne supprimera pas l'information de coreData, l'amenant à charger encore quand J'appelle un .reloadData()
. Je suis vraiment nouveau à Coredata et je ne sais pas comment sélectionner un article spécifique que je crée.Comment supprimer l'objet spécifique de base de données de TableView
Voici où je manipule la suppression:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
// handle delete (by removing the data from your array and updating the tableview)
recipes.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
}
Voilà comment je crée les éléments CoreData, si cela aide. De plus, j'ai un dépôt Git here si quelqu'un est prêt à regarder cette profonde
@IBAction func createNewRecipeButton(_ sender: Any) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let newRecipe = Recipe(context: context)
newRecipe.title = recipeTitleTextBox.text
newRecipe.instructions = recipeInstructionsTextBox.text
newRecipe.time = recipeTimeTextBox.text
(UIApplication.shared.delegate as! AppDelegate).saveContext()
navigationController!.popToRootViewController(animated: true)
}