I have an NSTreeController that is getting objects adding to it addObject:
method.
I have an NSOutlineView which has its content bound to the NSTreeController's arrangedObjects.
When I delete an object, as below
- (void) deleteSelectionConfirmed {
id selectedItem = [_outlineView itemAtRow:[_outlineView selectedRow]];
id obj = ((NSTreeNode *)selectedItem).representedObject;
NSManagedObjectContext *context = [self managedObjectContext];
[context deleteObject:obj];
NSError *error;
NSLog(@"%hhd", [[self managedObjectContext] hasChanges]);
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
} else {
NSLog(@"%@", [_hostController content]);
[_outlineView reloadData];
}
NSLog(@"%hhd", [[self managedObjectContext] hasChanges]);
}
It doesn't seem to be deleted.
The print out of my treeController content looks as such.
"<Host: 0x6080000b41c0> (entity: Host; id: 0x608000034180 <x-coredata://6E3284F6-D870-4DAF-A4E5-B6A4EB75021E/Host/p131> ; data: {\n hostname = asdfasdf;\n index = 0;\n children = \"<relationship fault: 0x60800022ecc0 'children'>\";\n title = gggg;\n username = asdf;\n})",
"<Host: 0x6080002a0960> (entity: Host; id: 0x608000032a80 <x-coredata://6E3284F6-D870-4DAF-A4E5-B6A4EB75021E/Host/p133> ; data: <fault>)"
)
The second line is the 'deleted' object. This is causing issues with the NSOutlineView to display a blank row. If I close an re-open my app however, dumping an NSFetchRequest shows my Managed object was actually deleted, and my NSOutlineView has the intended rows.
Am I missing something? Am I adding objects the wrong way? Should i be using a different binding? Any help is greatly appreciated.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; for (Host *host in fetchedObjects) { [_hostController addObject:host]; } – Kyle Browning-applicationDidFinishLaunching:
. – Ken Thomases