Finding/Saving in backgroundthread, displaying on mainthread #438

xxtesaxx opened this Issue Mar 27, 2013 · 1 comment


None yet
2 participants

i have a tableview with a refresh control which calls a method named reloadData. In this method, I instanciate a NSOperationQueue and add a block which finds all entities. To do this, I call

NSOperationQueue *queue = [[NSOperationQueue alloc] init]; = @"LoadRegionsQueue";
[queue addOperationWithBlock:^{
    NSArray *loadedRegions = [Region MR_findAllSortedBy:@"index" ascending:YES inContext:[NSManagedObjectContext MR_contextForCurrentThread]];
    [self performSelectorOnMainThread:@selector(dataReloadDidFinish:) withObject:loadedRegions waitUntilDone:NO];

Then I perfom a selector on the main thread where I assign the array to a instance variable and reload the tableview. In cellForRowAtIndexPath: I assign one of the entities property to the cells label.

-(void)dataReloadDidFinish:(NSArray *)loadedRegions{
    regions = [loadedRegions mutableCopy];
    [self.tableView reloadData];
    [self.refreshControl endRefreshing];

If the user taps in a cell, he can edit the text via a UITextField. In the textfields delegate, I get the related entity, and change the name

-(void)textFieldDidEndEditing:(UITextField *)textField{
    Region *region = (Region *)regions[currentlyEditingIndexPath.row];
    NSManagedObjectID *objectID = [region objectID];

    [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
        Region *regionToChange = (Region *)[localContext objectWithID:objectID]; = textField.text;
    } completion:^(BOOL success, NSError *error) {


Now the problem is: after chaning the text, I reload the tableview by drag&release. Somethimes the changed name is shown and sometimes the old name is shown. How can I make sure that the new name is saved and always be found?

I hope you can give me a hint what i am doing wrong.


tonyarnold commented Apr 8, 2014

Given the age of this issue, and the volume of issues we have to work through, I've decided to close this alongside a number of other older issues.

If you can still replicate the issue under the latest in-development version of MagicalRecord (3.0 at the time of writing), please feel free to re-open and one of @magicalpanda/team-magicalrecord will take another look. Thanks!

tonyarnold closed this Apr 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment