Re: NSSortDescriptor in core-data document app
Re: NSSortDescriptor in core-data document app
- Subject: Re: NSSortDescriptor in core-data document app
- From: Martin Hewitson <email@hidden>
- Date: Thu, 20 Aug 2009 21:22:24 +0200
Got it working. The problem was that I had "Auto Rearrange Content"
selected on the Entries array controller. I don't really understand
why this caused the problems I saw, but unchecking it makes the
problem go away.
Thanks for pointing me in this direction!
Martin
On Aug 20, 2009, at 9:12 PM, Martin Hewitson wrote:
Hi bryscomat,
Thanks for the swift reply.
I would implement a method in the File Owner of MyDocument.nib,
call it "titleSortDescriptors" or something of the like.
Then, in the nib file, I would bind the array controllers sort
descriptor to "File Owner.titleSortDescriptors".
On your suggestion, I tried that. It has the same effect as before.
If my saved document has two entries in it, the NSCollectionView
shows four entries after loading, but the second pair are kind of
dummies, which disappear as soon as I add another entry.
Also, with Core Data, what may be happening is that when you
programatically add an item, say on startup of the program, Core
Data will load the saved Entity from disk and also add the new one,
which may lead to duplicates. Check to make sure that's not
happening.
I don't add any entries programmatically - only when the user clicks
the 'add' button.
Still puzzled over this one.....
Martin
On Aug 20, 2009, at 12:29 PM, Martin Hewitson wrote:
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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