Coredata and NSOutlineView / NSTreeController
Coredata and NSOutlineView / NSTreeController
- Subject: Coredata and NSOutlineView / NSTreeController
- From: Samuel Williams <email@hidden>
- Date: Thu, 27 Jul 2006 13:28:32 +1200
Hi.
I am having a number of issues using Coredata. I will post the source
code in the morning, but primarily I am having a number of crashes,
which may be related to mistakes I have made, or may be due to the
nature of NSTreeController when combined with Coredata.
My delete: first responder for the NSOutlineView is implemented as
follows:
-(IBAction)delete:(id)sender{
NSManagedObjectContext *moc = [contentController managedObjectContext];
NSArray *selected = [contentController selectedObjects];
[[moc undoManager] setActionName:@"Delete Accounts/Tenures"];
[[moc undoManager] beginUndoGrouping];
@try {
NSEnumerator *enumerator = [selected objectEnumerator];
id obj;
while ((obj = [enumerator nextObject])) {
[moc deleteObject:obj];
}
[moc processPendingChanges]; //dying here
[contentView reloadData];
}
@finally {
[[moc undoManager] endUndoGrouping];
}
}
It is actually dying on the line [moc processPendingChanges]; with
EXC_BAD_ACCESS, or an NSZombie exception if I use that method of
debug. This is because I have this function here:
- (float)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:
(id)originalItem {
id item = [NSOutlineView originalItem:originalItem];
id parent = [NSOutlineView originalItem:[originalItem parentNode]];
// Causing a fault here seems to be a major problem
NSLog (@"heightOfRowByItem:%@", item);//, [item valueForKey:@"name"]);
if (parent && [parent isKindOfClass:[PMProperty class]] || [parent
isKindOfClass:[PMTenant class]])
return 17.0;
return 33.0;
}
The processPendingChanges call causes the NSOutlineView to refresh,
which in turn calls this function. However, at this point, the
pointer passed in as originalItem is actually invalid - it has
already been deallocated.. This causes the EXC_BAD_ACCESS or NSZombie
exception... This seems like a violation of the delegate
specifications.. but I am not sure, it may be something I am doing
wrong.
I don't know if this is useful, but this is the general area where
the issue is happening:
---- SOMEWHERE AFTER THIS OBJECT HAS BEEN RELEASED IT IS USED AS AN
ARGUMENT TO THE DELEGATE METHOD ABOVE ----
NSDecrementExtraRefCountWasZero
-[NSObject release]
__CFArrayReleaseValues
__CFArrayDeallocate
_CFRelease
-[_NSArrayControllerTreeNode prune]
-[_NSArrayControllerTreeNode updateSubnodes]
-[_NSArrayControllerTreeNode
observeValueForKeyPath:ofObject:change:context:]
-[NSObject(NSKeyValueObserverNotification)
didChangeValueForKey:withSetMutation:usingObjects:]
-[NSManagedObject didChangeValueForKey:withSetMutation:usingObjects:]
-[_NSNotifyingWrapperMutableSet removeObject:]
-[NSManagedObject(_NSInternalMethods)
_maintainInverseNamed:isToMany:oldDestination:newDestination:]
-[NSManagedObject(_NSInternalMethods)
_didChangeValue:forRelationship:named:withInverse:]
-[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:]
-[NSManagedObject didChangeValueForKey:]
-[NSManagedObject(_NSInternalMethods)
_setGenericValue:forKey:withIndex:flags:]
-[NSManagedObject(_NSInternalMethods) _propagateDelete]
-[NSManagedObjectContext(_NSInternalChangeProcessing)
_propagateDeletesUsingTable:]
-[NSManagedObjectContext(_NSInternalChangeProcessing)
_processDeletedObjects:]
-[NSManagedObjectContext(_NSInternalChangeProcessing)
_propagatePendingDeletesAtEndOfEvent:]
-[NSManagedObjectContext(_NSInternalChangeProcessing)
_processRecentChanges:]
---- MY DELETE FUNCTION CALLS processPendingChanges ----
I will do a more through analysis of this tomorrow and report back
here to see if it helps to solve this issue.
Any advice would be great I have been banging my head against this
wall for two or three days now.
Thanks in advance.
Mr Samuel Williams
Attachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden