Sorting contents of an NSCollectionView
Sorting contents of an NSCollectionView
- Subject: Sorting contents of an NSCollectionView
- From: Eli Bach <email@hidden>
- Date: Wed, 3 Mar 2010 15:39:00 -0700
I have a core-data app, with a view that shows a managed object, along with an NSCollectionView displaying related managed objects in 1 column, all hooked together primarily with bindings.
This works fine (selecting different objects automatically updates the collectionview and I can add/edit/delete related objects).
However, I would like to present the related records in the same order each time, as well as have new objects appear in a predicable location (namely, at one 'end' of the collectionview. I have an 'order' attribute, with NSInteger16 values, that I want to sort on.
Just adding a NSSortDescriptor to the NSArrayController that the NSCollectionView gets it's managed objects from only partially works:
1) it ONLY does the sort if I have a button that changes the sort AFTER the array is fully populated. Setting the sortDescriptor on the NSArrayController when the view loads, or even as the root managed object is changed, doesn't result in the collectionview being sorted
2) adding or deleting a related record [removing/adding objects for the collectionview] randomizes the order of the objects presented in the collectionview [either by calling add: on the NSArrayController or directly creating a new NSManagedObject for the relation]. The object is presented/removed, but the order is always rearranged randomly.
I've even tried (programmatically):
-add/delete record
-clear sort descriptor
-set sort descriptor
and it does do the sort. It only applies the sort if I hit a button that changes the sortDescriptor on the NSArrayController AFTER the collectionview gets fully populated.
Any ideas on the best way to keep the nsarraycontroller and/or the nscollectionview sorted all the time?
Eli
_______________________________________________
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