NSArrayController's contentArray and selectedIndexes don't match when sorted
NSArrayController's contentArray and selectedIndexes don't match when sorted
- Subject: NSArrayController's contentArray and selectedIndexes don't match when sorted
- From: Matt Neuburg <email@hidden>
- Date: Sun, 05 Mar 2006 11:36:57 -0800
- Thread-topic: NSArrayController's contentArray and selectedIndexes don't match when sorted
I am managing an NSTableView by binding it's columns in the ordinary way to
an NSArrayController. I have bound the NSArrayController's contentArray and
selectedIndexes to ivars in MyObject so that MyObject can examine what's
going on in the table without an outlet to either the table or to the
NSArrayController.
Except that it isn't working because if the user sorts the table, the
selectedIndexes and the contentArray don't match up any more.
Example:
* The table is not sorted. The user selects the first row. The
selectedIndexes tells me that item 0 is selected, and the object at index 0
of the contentArray is "Moe". So far so good.
* The user sorts the table and selects the first row. The selectedIndexes
tells me that item 0 is selected. The object at index 0 of the contentArray
is still "Moe". But the first row of the table says "Mannie". Ooops!
In other words, the selectedIndexes is describing the table as it actually
appears; it is not telling me the indexes in the underlying contentArray
that are selected.
So how can I learn what indexes of the contentArray are actually selected in
the table?
Now, you'll probably say: "Well, you schlumpf, just make an outlet to the
NSArrayController and examine its selectedObjects. That's way simpler than
what you were doing before anyway (because you no longer have to interpret
an NSIndexSet)." That's true, but still I don't really want to do that. I
really like the way bindings from the NSArrayController allow me to
"project" facts about the table directly into ivars of MyObject; to me, this
is a majorly cool feature of bindings. I like doing that better than
"peeking" into the NSArrayController through an outlet. So, is there a way
to do it my way, or is it just Tough Nuggies? m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden