я делаю app, который сохраняет информацию в CoreData и образце в пользователя в TableView. Я хотел бы удалить линии и данные, я думаю, что возможно помогать в этой секции?
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
Осуществите этот коды удаляют линии, но данные возвращаются, освежив app
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
objetos.remove(at: indexPath.item)
tableView.deleteRows(at: [indexPath], with: .automatic)
ты можешь использовать этот код внутри editingStyle
:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
switch editingStyle {
case .delete:
// remueve el item eliminado del modelo
let appDel: AppDelegate = UIApplication.shared.delegate as! AppDelegate
let managedObjectContext = appDel.persistentContainer.viewContext
let context = managedObjectContext
context.delete(tuArray[indexPath.row] as NSManagedObject)
tuArray.remove(at: indexPath.row)
do {
try context.save()
} catch _ {
}
// remueve el item eliminado del UITableView
self.tableView.deleteRows(at: [indexPath], with: .fade) default:
return
}
}