Sorting issues with NSTableView
Sorting issues with NSTableView
- Subject: Sorting issues with NSTableView
- From: "Patrick M" <email@hidden>
- Date: Wed, 18 Jul 2007 10:14:33 -0400
I have an NSTableview that lists files to be 'processed'. I want the list
to be sortable so users can scan the list more efficiently.
I have enabled column sorting using caseInsensitiveCompare (bindings). The
data is obtained from an array called "arrayFilesToProcess" using bindings
("value=" binding for the column to an array controller)
The display sorts the files listed correctly but the indexes of the selected
files, once sorted, do not point to the correct place in the actualy array.
as an example, the array may have the following entries:
A (index 0)
C (index 1)
D (index 2)
B (index 3)
When sorted (ascending, say, but descending will have a similar problem), it
will look like:
A
B
C
D
If I select B, this will correspond to index 1 in the display, but index 3
in the array. How can I map the display index to the array index without
creating my own code?
I manually update the array when files are added/removed (using
"willChangeKeyForValue"/"didChangeKeyForValue"). The array itself is just a
wrapper on a string, to hold the name of the file, with a 'value' accessor
that returns the file name.
The display updates fine, the list is sorted correctly and all files are
listed etc.. but once sorting occurs, the indexes returned no longer
correspond to the correct file in the array itself. This seems strange
since the display is getting the data correctly from the array, but then
returning a different index.
For example, my "Remove" button gets a list of the selected indexes and
tries to remove those selected 'files' from the list, but it is not possible
because I can't correlate the indexes returned from the display with the
objects they are supposed to point to in the array.
How do i find the object in the array associated with the index returned
from the display? Is there a way to sort the array when the column is
sorted so that the indexes always match? This seems overkill though. Is
there a setting in the array controller I am not setting properly?
Thank you in advance
_______________________________________________
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