Note that there are some explanatory texts on larger screens.

plurals
  1. POdelete one record from database using UITableView and Core Data
    primarykey
    data
    text
    <p>I am writing a simple app which lets users add entries to a database. The data is displayed in a UITableView. What I can't figure out is how to delete just one record from the database using the swipe-to-delete functionality of a tableview. I know that the code goes in this method:</p> <pre><code>-(void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated]; } </code></pre> <p>But I don't know how to fetch the record of the database that populates the cell that has been swiped.</p> <p>I have a method which deletes all cells when the user clicks on a button on the navigation bar:</p> <pre><code>-(void)deleteAll { NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Parameters" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSError *error; NSArray *items = [context executeFetchRequest:fetchRequest error:&amp;error]; for (NSManagedObject *managedObject in items) { [context deleteObject:managedObject]; } if (![context save:&amp;error]) { } [self.tableView reloadData]; } </code></pre> <p>But I don't how to customize this code to delete one record at a time. Any help to get me started would be appreciated.</p> <p>I have this method as well...I would think this would delete the record permanently but it doesn't...</p> <pre><code>- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [self.arr removeObjectAtIndex:indexPath.row]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } [self.tableView reloadData]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload