iPhone Core Data does not refresh table

Posted by Brian515 on Stack Overflow See other posts from Stack Overflow or by Brian515
Published on 2010-01-29T18:02:02Z Indexed on 2010/04/24 22:53 UTC
Read the original article Hit count: 300

Hi all,

I'm trying to write an application with Core Data, and I have been able to successfully read and write to the core data database. However, if I write to the database in one view controller, my other view controllers will not see the change until the app is closed then reopened again. This is really frustrating. I'm not entirely sure how to get the refresh - (void)refreshObject:(NSManagedObject *)object mergeChanges:(BOOL)flag method to work. How do I get a reference to my managed object?

Anyways, here's the code I'm using to read the data back. This is in the viewDidLoad method.

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Website" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"siteName" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];

NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if(mutableFetchResults == nil) {
    //Handle the error
}

[self setNewsTitlesArray:mutableFetchResults];
[mutableFetchResults release];
[request release];

[newsSourcesTableView reloadData];

Thanks for help in advance!

© Stack Overflow or respective owner

Related posts about iphonecoredatarecipes

Related posts about database