Advertisement
Guest User

Untitled

a guest
Dec 28th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  2. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3. // Delete the row from the data source
  4.  
  5. [self.folders removeObjectAtIndex:indexPath.row];
  6. NSMutableArray *newSavedFolders = [[NSMutableArray alloc] init];
  7.  
  8. for (Folder *folder in self.folders){
  9. [newSavedFolders addObject:[self folderWithName:folder.name]];
  10. }
  11.  
  12. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  13.  
  14. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  15. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  16. }
  17.  
  18. -(Folder *)folderWithName:(NSString *)name {
  19. id delegate = [[UIApplication sharedApplication] delegate];
  20. NSManagedObjectContext *context = [delegate managedObjectContext];
  21.  
  22. Folder *folder = [NSEntityDescription insertNewObjectForEntityForName:@"Folder" inManagedObjectContext:context];
  23. folder.name = name;
  24. folder.date = [NSDate date];
  25.  
  26. NSError *error;
  27. if (![context save:&error]) {
  28. //we have an error
  29. }
  30.  
  31. return folder;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement