Re: Sorting issues with NSTableView
Re: Sorting issues with NSTableView
- Subject: Re: Sorting issues with NSTableView
- From: Keary Suska <email@hidden>
- Date: Wed, 18 Jul 2007 09:37:01 -0600
- Thread-topic: Sorting issues with NSTableView
on 7/18/07 8:14 AM, email@hidden purportedly said:
> 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 you see, table sorting doesn't change the order of the model array.
> 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?
It sounds like your approach is a good candidate for implementing indexed
accessor methods. This way you can use the controller's action method(s),
such as -remove:, and capture when they happen.
Otherwise, you will need to manually determine indexes using
-indexOfObject:, getting the controller's select objects using
-selectedObjects:.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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