简体   繁体   中英

Unable to delete row/coredata

In my app I have a Table view with values from a mapkit. I can edit the table, delete the row, but when the app starts over, the same deleted rows are still there....How can I fix this? The code for the editing:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {

     [_locations removeObjectAtIndex:[indexPath row]];

     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

     [tableView reloadData];
 }

Any tips? Thank you

  1. Load the data from core data using a NSFetchedResultsController .
  2. Implement the delegate function to update your views when change occur.
  3. When you delete something delete enqueue a block to delete it from core data. (if you are using NSPersistentContainer use performBackgroundTask: ).
  4. Don't update your views. This will happen automatically because of the delegate callback that you implemented in step 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM