Re: Opening a window in Core Data application
Re: Opening a window in Core Data application
- Subject: Re: Opening a window in Core Data application
- From: Joshua Scott Emmons <email@hidden>
- Date: Thu, 30 Mar 2006 14:19:24 -0600
1. Open the window automatically when the user adds a new record. I
am using an ArrayController named ArchiveMO to manage the data, and
I have overridden the awakeFromInsert method to automatically set
the date to the current date ... The awakeFromInsert method seems
like the ideal place to add this code
This sounds a little confused to me. To the best of my knowledge, the
only -awakeFromInsert is a method in NSManagedObject, not
NSArrayController. Maybe you mean -awakeFromNib?
Either way, I don't think that would be a good place for this code. -
awakeFromNib only fires once when the nib is first loaded, not
whenever you add a record. And while NSManagedObject's -
awakeFromInsert fires at the correct times, putting code in there to
open a window would require your Model to know something about your
View -- a design no-no.
A better way, I think, is to change your "+" button. Instead of
wiring it directly to NSArrayController, create an action in your
controller called "-addRecordAndOpenWindow:" or some such. Wire the
button to that. Have -addRecordAndOpenWindow:'s call
NSArrayController's -add: method manually. After that's done (and
you've checked to make sure the operation's completed successfully),
have it open your window.
Though it occurs to me that this behavior could be considered
annoying by some -- I would advise putting a preference in there that
allows the user to select whether the window opens automatically or not.
2. I'd also like to be able to open the edit window when the user
double-click's on an archive. I don't even know where to start with
this.
The first thing to keep in mind is that, by default, double-clicking
on a table cell causes the cell to become editable right there in the
table. This is might be what the user expects to happen, so I'd again
advise caution in modifying this behavior. Especially as you seem to
have a perfectly functional "edit" button right there.
That said, I think the trick you're looking for is to make your cells
uneditable, and then to use -setDoubleAction: to specify the custom
code that will launch your window. The rest should be taken care of
by bindings. See http://tinyurl.com/kcgoc for details.
Hope that helps,
-Joshua Emmons
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden