Language/Objective-C

CoreData DB reload

아르비스 2011. 3. 29. 14:03

// DB update ..sncap

- (void)updateSet{

    // DB update

//    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    [[NSNotificationCenter defaultCenter] addObserver:self 

                                             selector:@selector(importContextDidSave:) 

                                                 name:NSManagedObjectContextDidSaveNotification

                                               object:[self managedObjectContext]];

//    

//    [[self managedObjectContext] save:nil];

//    [[self managedObjectContext] release];

}


- (void)updateCompleted{

//    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];


    [[NSNotificationCenter defaultCenter] removeObserver:self 

                                                    name:NSManagedObjectContextDidSaveNotification 

                                                  object:[self managedObjectContext]];

}


- (void)importContextDidSave:(NSNotification *)saveNotification {

//    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    // Merging changes causes the fetched results controller to update its results

    [[self managedObjectContext] mergeChangesFromContextDidSaveNotification:saveNotification]; 

}

//~sncap


DB를 다른곳에서 갱신하고, 해당 DB를 읽을 경우, 
이전에 읽었던 DB의 data는 변경(갱신)이 되지 않는다..

위의 함수처럼 작성해서 적용하면 된다 하는데.....
뭘 잘 못한걸까? 제대로 DB가 갱신이 되지 않는다..ㅠㅠ