hi :) I have a similar problem, for example, in Working with the same NSManagedObjectContext on several tabs
background:
My managedObjectContext (hereinafter MOC) is initialized in my appDelegate class and passed through tt to several tabs using
myViewController.managedObjectContext = self.managedObjectContext;or in the init method with self.managedObjectContext = pContext;
stream: first view is a simple list of collections. Collections are retrieved using NSFetchedResultsController ( myViewController : UITableViewController<NSFetchedResultsControllerDelegate>). By choosing one of them, you move deeper, but still skip this MOC.
In the next controller (detailViewController), I list some elements of this collection that I can interact with (for example, to set radio buttons).
I also have editObjectContext:
NSManagedObjectContext* editingContext = [[NSManagedObjectContext alloc] init];
[editingContext setPersistentStoreCoordinator:[managedObjectContext persistentStoreCoordinator]];
self.editingObjectContext = editingContext;
Now my problem is: because my opinion has to spin, I use the following trick:
DetailsView *localAct = [[DetailsView alloc] initWithManagedObjectContext:managedObjectContext ... ]
DetailsView *localSen = [[DetailsView alloc] initWithManagedObjectContext:managedObjectContext ... ]
UITableView *localContainerView = [[UITableView alloc] init];
self.containerView = localContainerView;
[localContainerView release];
[containerView addSubview:actuatorView];
self.tableView = containerView;
further, I have a button for controlling these elements (which of them should be shown and which should not). This button simply reloads the table with the new fetchResult.
- (void) manageItems{
managing = !managing;
[viewController setIsManaging:managing];
self.fetchedResultsController = nil;
NSError *error = nil;
[[self fetchedResultsController] performFetch:&error];
[self reloadData];
[self updateBarButton];
}
The method for placing elements in context looks like this:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSSet* set = [sen filteredSetUsingPredicate:predicate];
if( [set count] > 0 )
{
for( Act* act in set )
{
[editingObjectContext deleteObject:act];
}
}
else
{
Act* act = [NSEntityDescription insertNewObjectForEntityForName:@"Act" inManagedObjectContext:editingObjectContext];
}
NSError *error = nil;
[[detailView fetchedResultsController] performFetch:&error];
[self.containerView reloadData];
[detailView reloadData];
}
but after I selected the elements in the managed view and click save (manageItems), the view does not show them: / I need to switch the tab or switch to another controller (parent or deeper) to implement it, my ViewWillAppear method:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
DetailsView *detailView = se ? senView : actView;
[detailView.fetchedResultsController performFetch:nil];
[self.tableView reloadData];
}
and viewWillDisapper calls
- (void)saveChanges
{
if( ![editingObjectContext hasChanges] )
return;
}
Verison, , , ...:/ , MOC , . "manageItems" , ( DetailsView )...
- , ( , , . self.tableView/detailView/self.containerView refresh :/).
: "editObjectContext save:" , .
handleChangeResponse: Error Domain = NSCocoaErrorDomain Code = 133020 " . (Cocoa 133020.)" UserInfo = 0x4d8bb90 {conflictList = ( "NSMergeConflict (0x5a2fac0) NSManagedObject (0x5a46a80) " 0x5a46420 " oldVersion = 7 newVersion = 8 = {\n iconName = noicon;\n [...];\n} = {\n iconName = noicon;\n [...]\n}" )}
(, ), :)
:)