Error when deleting item from tableview in swift

前端 未结 1 692
走了就别回头了
走了就别回头了 2021-01-16 03:39

I am trying to implement a delete functionality in my app allowing users to delete information stored in core data and presented through a table view.

here is my cod

相关标签:
1条回答
  • 2021-01-16 04:16

    Delete the core data item and let the delegate callbacks take care of deleting the table view row:

    if editingStyle == .Delete {
      let item = self.fetchedResultsController.objectAtIndexPath(indexPath) as NSManagedObject
      self.managedObjectContext.deleteObject(item)
    }
    

    The row deletion happens in the delegate callback controller:didChangeObject:atIndexPath: forChangeType:newIndexPath:

    if type == .Delete { 
      self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    }
    
    0 讨论(0)
提交回复
热议问题