Hi Ron,

thanks for the reply. I agree just storing the "last known thing that the user was looking at" is doable, wouldn't require a non-MVC model- based hack, and would make for a much smaller user defaults file - as there's only 3 selections being stored (1x Company, 1x Department and 1x Employee), not A x B x C selections. However, I need to store each Company's and each Department's last known selection as the custom control / cell displays meta-info about those selections, whether or not it's what the user is currently viewing.

So to try to stick to an iTunes analogy (it's actually a neural network application, hence trying to use an easier analogy), I have a playlist tableview over on the left, which, as well as telling you the playlist's name (in the tableview's cell), also tells you what was last being played in that playlist and several other things about the contents of its last selected item.

So I'm thinking storing in the defaults a 1:1 pair of each Company & its last selected Department, and then another 1:1 pair of each Department and its last selected Employee, would be better (for me). I can still picture a million faults firing during the app quitting stage though :-!

Thanks for the ideas,
Ken

p.s. Mail is one up on iTunes, which remembers which playlist you were in before quitting, but not which track was being played.

On 25 Jan 2010, at 10:05, Ron Fleckner wrote:

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


Hi Ken,

I think this would be a job for user defaults.  So at app shut down,
I'd just intervene at that point and write the current selection
details to user defaults.  No need to futz with your model.  Of
course, you'd only then have the selection for one of the companies,
but that is sort of what Mail does.  It remembers the last selected
email and the last selected mailbox, but no other.

Ron

- - - - - - - - - -
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