Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I maintain display order in UITableView using Core Data?
    primarykey
    data
    text
    <p>I'm having some trouble getting my Core Data entities to play nice and order when using an UITableView.</p> <p>I've been through a number of tutorials and other questions here on StackOverflow, but there doesn't seem to be a clear or elegant way to do this - I'm really hoping I'm missing something.</p> <p>I have a single Core Data entity that has an int16 attribute on it called "displayOrder". I use an NSFetchRequest that has been sorted on "displayOrder" to return the data for my UITableView. Everything but reordering is being respected. Here is my (inefficient) moveRowAtIndePath method:</p> <pre><code>- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { NSUInteger fromIndex = fromIndexPath.row; NSUInteger toIndex = toIndexPath.row; FFObject *affectedObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex]; affectedObject.displayOrderValue = toIndex; [self FF_fetchResults]; for (NSUInteger i = 0; i &lt; [self.fetchedResultsController.fetchedObjects count]; i++) { FFObject *otherObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:i]; NSLog(@"Updated %@ / %@ from %i to %i", otherObject.name, otherObject.state, otherObject.displayOrderValue, i); otherObject.displayOrderValue = i; } [self FF_fetchResults]; } </code></pre> <p>Can anyone point me in the direction of a good bit of sample code, or see what I'm doing wrong? The tableview display updates OK, and I can see through my log messages that the displayOrder property is being updated. It's just not consistently saving and reloading, and something feels very "off" about this implementation (aside from the wasteful iteration of all of my FFObjects).</p> <p>Thanks in advance for any advice you can lend.</p>
    singulars
    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.
 

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