• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSSortDescriptor in core-data document app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSSortDescriptor in core-data document app


  • Subject: NSSortDescriptor in core-data document app
  • From: Martin Hewitson <email@hidden>
  • Date: Thu, 20 Aug 2009 19:29:45 +0200

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@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: Force crash a cocoa app for Crash Reporter testing
  • Next by Date: IB connections with view swapping?
  • Previous by thread: Re: Force crash a cocoa app for Crash Reporter testing
  • Next by thread: Re: NSSortDescriptor in core-data document app
  • Index(es):
    • Date
    • Thread