Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading core data into array, then populating table view, reordering array's objects doesnt persist
    primarykey
    data
    text
    <p>First let me tell you what im trying to do. Load data into array(from core data entity), populate table view, if user wants, reorder cells and update the array. </p> <p>Thats it. </p> <p>I have found my problem, i just dont know how to fix it:</p> <p>I am loading my Entities data/attributes into an array and populating my tableview with the data (BELOW BEHOLDS THE PROBLEM):</p> <pre><code>-(void)viewWillAppear:(BOOL)animated{ if (self.context == nil) { self.context = [(RootAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; } NSFetchRequest *request = [[NSFetchRequest alloc]init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"HandgunAmmo" inManagedObjectContext:self.context]; [request setEntity:entity]; NSError *error; //PROBLEM!!! the 2 lines below this. NSMutableArray *array = [[self.context executeFetchRequest:request error:&amp;error] mutableCopy]; [self setTableArray:array]; [self.ammoTable reloadData]; [super viewWillAppear:YES]; } </code></pre> <p>SO at this point the table view is loaded with data (accounting for <code>cellForRow</code> being called)</p> <p>The user moves a few cells around, and i update the array as follows:</p> <pre><code>- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { // fetch the object at the row being moved NSString *r = [self.tableArray objectAtIndex:fromIndexPath.row]; // remove the original from the data structure [self.tableArray removeObjectAtIndex:fromIndexPath.row]; // insert the object at the target row [self.tableArray insertObject:r atIndex:toIndexPath.row]; [self.ammoTable reloadData]; } </code></pre> <p>As you can see the code for reordering the array should work. </p> <p>But, in the <code>viewWillAppear</code> method, I am loading the entities attributes into the array again and using it to populate the table view which is the problem. When i update the array, its not updating the order of the objects inside of the entity. Does anyone know how to update that? I would really appreciate it! </p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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