Re: programmatically sorting an NSTableView
Re: programmatically sorting an NSTableView
- Subject: Re: programmatically sorting an NSTableView
- From: James Walker <email@hidden>
- Date: Wed, 13 Jul 2011 12:44:25 -0700
On 7/12/2011 11:43 PM, Ken Thomases wrote:
On Jul 12, 2011, at 9:24 PM, James Walker wrote:
On 7/12/2011 6:14 PM, Ken Thomases wrote:
On Jul 12, 2011, at 5:36 PM, James Walker wrote:
On 7/12/2011 2:04 PM, Ken Thomases wrote:
Invoking -setSortDescriptors: on the array controller does sort it (or should).
Back on 10.4, it may have been necessary to follow that with a call to -rearrangeObjects.
-[NSArrayController setSortDescriptors:] alone doesn't work for me even on 10.6, but that combined with -[NSArrayController rearrangeObjects] does the trick. That is, I set use setSortDescriptors: once, and use rearrangeObjects whenever I add new items to the table.
Is your array controller bound to its content, or are you setting that programmatically? If it's bound, then it ought to rearrange its objects when they are added. The fact that it doesn't suggests that you aren't updating the property to which it is bound in a KVO-compliant manner.
The table column is bound to the array controller using IB.
OK, but I was trying to get at the question of from where the array controller gets its content. Is its contentArray binding bound? Or are you setting its content programmatically using -initWithContent: or -setContent:?
Oh... I wasn't doing anything about the content, I figured that the
array controller would default to using some mutable array on its own,
in the same way that the NSObjectController is documented to default to
using an instance of NSMutableDictionary as its content.
Today I tried binding the contentArray of the array controller to a
mutable array property of my window controller, but I still don't get
sorting without explicitly calling rearrangeObjects.
I was adding new items using -[NSArrayController addObject:]. What's the better way?
That's fine and should work. I don't know why the array controller isn't re-arranging its content. Maybe my understanding of that behavior is wrong. When you weren't calling -rearrangeObjects, were the added objects showing up in the table at all (but maybe in the wrong order)?
Yes; without calling rearrangeObjects, new objects just get tacked on to
the end in the order they are added.
--
James W. Walker, Innoventive Software LLC
<http://www.frameforge3d.com/>
_______________________________________________
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