• 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
sort descriptors of NSArrayController are lost (WAS: Re: NSArrayController, saving and reloading sort descriptors)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sort descriptors of NSArrayController are lost (WAS: Re: NSArrayController, saving and reloading sort descriptors)


  • Subject: sort descriptors of NSArrayController are lost (WAS: Re: NSArrayController, saving and reloading sort descriptors)
  • From: Knud Hinnerk Möller <email@hidden>
  • Date: Thu, 15 Mar 2007 16:42:20 +0000

Thanks Aurélien!

Could this also be the reason for another weird thing:

- when the app starts set the sort descriptors be of an NSArrayController to an instance of my KNGraphSortDescriptor class:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
   NSSortDescriptor* graphSortDesc = [[[KNGraphSortDescriptor alloc]
      initWithKey: @"label"
      ascending: YES
      selector: @selector(caseInsensitiveCompare:)] autorelease];

[graphArrayController setSortDescriptors: [NSArray arrayWithObject: graphSortDesc]];
}


- initially, this works
- when I change the sort direction in a table bound to the controller (i.e. click in the table header), the sort descriptor is replaced by a vanilla NSSortDescriptor, and my custom sorting is gone


What happened here?

Cheers,
Knud

Am 14.03.2007 um 15:40 schrieb Aurélien Hugelé:

Knud,

I think that the reason is quite simple:

when you sort by clicking on a table column, the sort is performed IN MEMORY using cocoa sort, that is KVC compatible, and calls your anyLabel method, and the sort descriptor is set on the array controller.
Then this sort descriptor is stored to user default and you relaunch the app, when the array controller get its awakeFromNib when loaded from the nib, a delayed fetch is performed to fillup the content of the array controller. In order to optimize the loading, apple decided to use the fetch to get AND SORT the data in a single batch. The problem is that when you add a sort descriptor (in that case the one from the user default) to a fetch, the sorting is done by SQLite (if you have a SQL store), and thus the key must be hardcoded as an attribute in database to be accessible/ known by SQLite... KVC won't work here...


You can customize you array controller to change the sort descriptor on the fly when the fetch is executed so that it does not sort with SQLite backend, then set the sort descriptor once the fetch has been execcuted to perform the sorting in memory, the cocoa way...

Seems a little complicated huh?

On 14 mars 07, at 15:00, Knud Hinnerk Möller wrote:

Hi,

can anyone help me with the following problem:

- I have an NSArrayController for a subclass of NSManagedObject called KNResourceNode
- KNResourceNode has a fake access method "anyLabel" (i.e. not giving access to any real ivar or attribute)
- in IB I specify the sort descriptor for a table column that is bound to the controller as such: (key: "anyLabel", selector: caseInsensitiveCompare, order: ascending) - this works fine
- when the application terminates, I write the controller's sort descriptors to NSUserDefaults
- I bind the controllers sort descriptors to NSUserDefaults (so that the sorting is remembered)


Now, this all works fine when I specify a particular contentSet binding for the controller. When I don't (i.e. I just want all instances of KNResourceNode), I get the following error on startup (when then binding is taking place, I suppose) - but only for sort descriptors that use "anyLabel"! Not for any other keys, which might be actual attributes of KNResourceNode.

*** NSRunLoop ignoring exception 'Unknown key in query. anyLabel' that raised during posting of delayed perform with target 376330 and selector 'invokeWithTarget:'

I hope I explained this well enough. Does anyone know what is going on here?

Cheers,
Knud

-------------------------------------------------
Knud Möller, MA
+353 - 91 - 495086
Digital Enterprise Research Institute
  National University of Ireland, Galway
Institiúid Taighde na Fiontraíochta Digití
  Ollscoil na hÉireann, Gaillimh


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
40gumitech.com


This email sent to email@hidden



------------------------------------------------- Knud Möller, MA +353 - 91 - 495086 Digital Enterprise Research Institute National University of Ireland, Galway Institiúid Taighde na Fiontraíochta Digití Ollscoil na hÉireann, Gaillimh


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: sort descriptors of NSArrayController are lost (WAS: Re: NSArrayController, saving and reloading sort descriptors)
      • From: Scott Stevenson <email@hidden>
References: 
 >NSArrayController, saving and reloading sort descriptors (From: Knud Hinnerk Möller <email@hidden>)
 >Re: NSArrayController, saving and reloading sort descriptors (From: Aurélien Hugelé <email@hidden>)

  • Prev by Date: NSTextView: container size and text alignment
  • Next by Date: Re: Reordering of outlineview objects after rename
  • Previous by thread: Re: NSArrayController, saving and reloading sort descriptors
  • Next by thread: Re: sort descriptors of NSArrayController are lost (WAS: Re: NSArrayController, saving and reloading sort descriptors)
  • Index(es):
    • Date
    • Thread