Doh... sorry about the length of that message, it included the various draft versions, so please ignore it (unless you like seeing the pain someone goes through when trying to state their problem concisely!)

Below is the properly edited version, and I'd be grateful for any advice you can give.

(Walks away with tail between his legs)
Ken

On 25 Jan 2010, at 9:38, Tabb, Ken wrote:

Hi folks,

I have a Core Data app that needs to remember state of selected items
between launches.

The app's UI is a bit like iTunes (containers / playlists down the
side and contents show in a big tableview), except that there are 3
layers of containment, so rather than Playlists and Tracks, you could
think of it as Companies, Departments & Employees.

What I'd like is for each Company to remember the last selected
Department in it, and for each Department to remember the last
selected Employee in it. I'd like to remember this between launches.
To clarify, I'm not just wanting to remember which Company / Dept /
Employee the user was last looking at before they quit, but for each
Company & Department, what the last selected object within it was.

So in other words say the user clicks on "Apple", and then on the
"Upper Echelons" Department, and then "Steve Jobs". After this, the
user then clicks on a different company, say... Slate Computing LLC...
and on some department and employee within it. The user then quits.

When the user relaunches, I'd like it to go straight to showing the
Slate Computing LLC + selected department + selected employee.
However, if the user clicks on Apple, I'd like it to remember that
they were last looking at its "Upper Echelons" department, and "Steve
Jobs" in particular.

The hack that I can think of to do this would be for each Company
entity to have a "selectedDept", and for each Department entity to
have a "selectedEmployee" relationship, but this kind of breaks MVC...
other than it being easy to implement, the model shouldn't care what
the user was last looking at. Furthermore if I ever implement multi-
client access, then it can only remember (in the central data
repository) what 1 user was last looking at, so if Fred was last using
the app and I launched it, it would start me up with Fred's last
selection if this is stored inside the model.

What is the preferred MVC design for implementing this kind of
functionality?

I could be barking up the wrong tree here but I'm thinking I should
override the Company & Department array controllers, so that each time
their selection changes, I get the managed object IDs for the new
selection, and write it out to a preference list (or a separate per-
user persistent store), and reading from this when the user selects
something else, so we know which child item to select by default for
them. Would this break when the managed objects go from being
temporary (i.e. new) to permanent (i.e. saved) though? Or should I
only write the file / 2nd store when the app is quitting (after
everything that's staying has been committed)?

Hope I've stated my problem well enough - if anything needs
clarification let me know.
Thanks in advance for any help you can give,
Ken

- - - - - - - - - -
Dr. Ken Tabb
Mac & UNIX Developer - Health & Human Sciences
Machine Vision & Neural Network researcher - School of Computer Science
University of Hertfordshire, UK


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to