0
votes

I am only seeing the saved context after I restart my app. I have two view controllers, one that allows a user to save a core data record and the other to display. When I save a new record, then go to the table view to see all the records created, I do not see the new record. This is how I create a record:

NSManagedObjectContext *context = [self managedObjectContext];
    Property *myProperty = [NSEntityDescription
                            insertNewObjectForEntityForName:@"Property"
                            inManagedObjectContext:context];
    myProperty.aptDescription = curProperty.description;
    NSError *error;
    [context save:&error];
    [appDelegate saveContext];

And then i retreive it doing this:

ATAppDelegate *appDelegate = (ATAppDelegate *)[[UIApplication sharedApplication]delegate];
    _managedObjectContext = [appDelegate managedObjectContext];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription
                                   entityForName:@"Property" inManagedObjectContext:_managedObjectContext];
    [fetchRequest setEntity:entity];
    NSError *error;
    self.myProperties = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];

But like I said the new object is not shown when I go back into the table view immediately after creating the record. What is the issue?

1
You don't need to save the context twice. Log the error variables you're using. - Wain
Are you getting any errors back, are you reloading the table data? - Ben Avery
Use a fetchedResultsController in conjunction with your UITableView - see here developer.apple.com/library/ios/documentation/CoreData/… - Duncan Groenewald

1 Answers

1
votes

Sounds like you are not implementing the delegate methods of the NSFetchedResultsController properly. Although you did not share any of your view code so it is impossible to be certain.

In addition, after a save you are not checking the BOOL return from the -save:. You should always, always, always check that BOOL and at least log the error. You could be throwing an error and never know it.