Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- // Delete the row from the data source
- [self.folders removeObjectAtIndex:indexPath.row];
- NSMutableArray *newSavedFolders = [[NSMutableArray alloc] init];
- for (Folder *folder in self.folders){
- [newSavedFolders addObject:[self folderWithName:folder.name]];
- }
- [tableView deleteRowsAtIndexPaths:@[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
- }
- -(Folder *)folderWithName:(NSString *)name {
- id delegate = [[UIApplication sharedApplication] delegate];
- NSManagedObjectContext *context = [delegate managedObjectContext];
- Folder *folder = [NSEntityDescription insertNewObjectForEntityForName:@"Folder" inManagedObjectContext:context];
- folder.name = name;
- folder.date = [NSDate date];
- NSError *error;
- if (![context save:&error]) {
- //we have an error
- }
- return folder;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement