Dear all,

I have a core-data document based app which uses an NSCollectionView to display entries of a single entity (Entry) in the data model. In MyDocument.m In this document class I have an ivar which holds a reference to the NSArrayController that is in the MyDocument nib. That array controller is set to the entity mode and holds the Entry entities; its managedObjectContext is bound to the File's Owner managaedObjectContext. So far this is all standard stuff and it works as it should. I can add and remove Entries, etc. The problem comes when I try to sort the contents of the array. In MyDocument.m I implemented windowControllerDidLoadNib: as follows:

- (void)windowControllerDidLoadNib:(NSWindowController *)windowController
{
        [super windowControllerDidLoadNib:windowController];
        // user interface preparation code
        
NSSortDescriptor *entrySortDesc = [[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES] autorelease];
        NSArray *entrySortDescArray = [NSArray arrayWithObject:entrySortDesc];
        [entryArrayController setSortDescriptors:entrySortDescArray];   
}

Now I do the following in the running app:

1) add a single entry to the empty document, and my NSCollectionView shows a single row - fine
2) save the document to disk
3) quit and relaunch
4) load the saved document
5) my NSCollectionView now shows two entries, though the second is a kind of ghost of the first: I can't select it or anything, and if I add a new entry, the this 'ghost' is overwritten

Without the sort descriptors being set, I don't get the strange behaviour detailed in 5).

Does anyone have any advice how I can start to debug this? I guess I'm doing something wrong - perhaps setting the descriptors on the entryArrayConrtroller too early...

Kind regards,

Martin

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
    Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: [email protected]
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to