Guest User

Untitled

a guest
Jan 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. return YES;
  4. }
  5.  
  6.  
  7.  
  8. // Override to support editing the table view.
  9. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  10. {
  11. if (editingStyle == UITableViewCellEditingStyleDelete) {
  12. // Delete the row from the data source
  13. NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
  14. [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
  15.  
  16. [self saveContext];
  17. }
  18. }
  19.  
  20. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  21. return UITableViewCellEditingStyleDelete;
  22. }
  23.  
  24. - (IBAction)setEditMode:(id)sender {
  25. [self.tableView setEditing:YES animated:YES];
  26. }
  27.  
  28. - (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
  29. forRowAtIndexPath:(NSIndexPath *)indexPath {
  30.  
  31. if(editingStyle == UITableViewCellEditingStyleDelete) {
  32.  
  33. //Get the object to delete from the array.
  34. Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:indexPath.row];
  35. [appDelegate removeCoffee:coffeeObj];
  36.  
  37. //Delete the object from the table.
  38. [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  39. }
  40. }
Add Comment
Please, Sign In to add comment