Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to preserve an NSArrayController's selection when an item's value changes?



I'll do my best to describe this, but will probably omit something important:

Imagine that I have a table view that contains animals. Each animal has a species 'e.g Dog' and a classification 'e.g Mammal'. New animals get added to this table intermittently from an external source. This table is working perfectly, but is needed to explain the next table better.

I have another table which is used to filter the animals displayed in the first table by their classification. E.g The table might consist of:

Mammal
Bird
Fish

The array controller for this table is observing changes to the animals array controller.

When the user clicks on one of the items in this array the animals table nicely updates to show only those animals with the selected classification (by filtering in arrangeObjects).

So imagine we have Bird selected in this list. A new animal comes in from our external source and all the bindings code works nicely to update the animals table controller which causes the classification controller to rebuild its array. As things currently stand, Birds is still selected in the this list and is what I want to happen.

Now onto the problem:

I recently changed the classification controller so that the NSStrings that it keeps in its array also have a bracketed count in them so we can see how many there are of each type:

Mammal (27)
Bird (5)
Fish (12)

If I have the 'Bird (5)' row selected and another bird comes in, then the end result is that although my classification table shows there now being 6 birds, the 'Mammal (27)' row gets selected and the animals table is now showing only mammals, not birds. I am guessing that this happens because the array controller is not able to match up my 'Bird (5)' row with anything, and so it just selects the first row in the table.

So what I need to know is if it is possible to intervene in how NSArrayController tries to match up the selection. Does it all just come down to an isEqualTo test?

Hope that all makes sense

Matt Gough
Softchaos Limited
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.