Re: Sorting issues with NSTableView
Re: Sorting issues with NSTableView
- Subject: Re: Sorting issues with NSTableView
- From: "Patrick M" <email@hidden>
- Date: Wed, 18 Jul 2007 13:24:15 -0400
> 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.
>
It's not clear in what sense this is "strange"?
The table view is presenting a representation of the data. In the
cases of sorting and filtering, it does not actually change the data.
It is strange, from my perspective, that it returns the dislay index, which
is of no use in any context, except maybe in updating the display manually,
but that is working fine.
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.
>
Is there any reason why you cannot simply ask the array controller to
remove the items?
e.g. connect the Remove button to the remove: method of the array
controller, or send the array controller a
removeObjectsAtArrangedObjectIndexes: message?
The remove button might work in this case, though I iwll ultiamtely apply
this solution to another case where the displayed array is kept in synch
with another associated data array, and the indexes must match in that case
as well. The remove button would not work in that case, and for adding, i
present a file dialog to select files, which does not work with the add:
method of the array..
How do i find the object in the array associated with the index
> returned
> from the display?
>
id objectAtTheDisplayIndex =
[[arrayController arrangedObjects] objectAtIndex:theDisplayIndex];
I have not tried this, but it seems to use the display index to index into
the array manually. If the array is not sorted (as mine is not) this will
return the wrong object...
I have since found that
[myArrayController removeObjects:[myArrayController selectedObjects]];
works.
_______________________________________________
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