Advertisement
RRK

Updating store

RRK
Nov 8th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     - (void)rightSwipe:(UIGestureRecognizer *)gestureRecogniser {
  2.     // A right swipe sets the status to completed
  3.     NSInteger row = [self rowForRecogniser:gestureRecogniser];
  4.            
  5.     if (row == NSNotFound)
  6.     {
  7.         return;
  8.     }
  9.  
  10.        NSMutableArray *taskArray = [[self.controller fetchedObjects]mutableCopy];
  11.         Task *task = [taskArray objectAtIndex:row];
  12.  
  13.         for (int i = 0; i < [taskArray count]; i++)
  14.             {
  15.                 Task *task1 =  [taskArray objectAtIndex:i];
  16.                 if(task1.completedStatus == FALSE)
  17.                 {
  18.                     m_position = i;
  19.                     m_finalIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
  20.                 }
  21.             }
  22.            
  23.             task.completedStatus = YES;
  24.            
  25.             id obj = [noteCategoryArray objectAtIndex:row];        
  26.             [taskArray removeObjectAtIndex:row];
  27.             [taskArray insertObject:obj atIndex:m_position];      
  28.            
  29.             [m_tableView beginUpdates];
  30.             NSIndexPath *currentIndexPath = [NSIndexPath indexPathForRow:row inSection:0];
  31.             [m_tableView moveRowAtIndexPath:currentIndexPath toIndexPath:m_finalIndexPath];
  32.         [m_tableView endUpdates];
  33.  
  34.         float i = 0.0f;
  35.         for (NSManagedObject *mo in taskArray)
  36.         {
  37.             [mo setValue:[NSNumber numberWithFloat:i++] forKey:@"displayOrder"];
  38.            
  39.             NSError *error = nil;
  40.            
  41.             if (![self.managedObjectContext save:&error])
  42.             {
  43.                 NSString *msg = @"An error occurred when attempting to save your user profile changes.\nThe application needs to quit.";
  44.                 NSString *details = [NSString stringWithFormat:@"%@ %s: %@", [self class], _cmd, [error userInfo]];
  45.                 NSLog(@"%@\n\nDetails: %@", msg, details);
  46.             }
  47.            
  48.             // re-do the fetch so that the underlying cache of objects will be sorted
  49.             // correctly
  50.            
  51.             if (![self.controller performFetch:&error])
  52.             {
  53.                 NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  54.                 abort();
  55.             }
  56.         }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement