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: Wayne Pascoe <email@hidden>
- Date: Thu, 30 Mar 2006 21:41:38 +0100
On 30 Mar 2006, at 21:19, Joshua Scott Emmons wrote:
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?
Sorry - I borked that by confusing my array controller with my Entity.
My Entity is an ArchiveMO object - this is a subclass of
NSManagedObject - my Doh!
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.
That's been pointed out to me - I don't think I understand the MVC
pattern (or design patterns for that matter :(), but I'm starting to
understand that my data model shouldn't know anything about the
windows or views that manage it. Is that roughly right ?
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.
Ok - that sounds workable. Sorry to be a total luser, but can you
point me at some documentation / code that discusses accessing array
controllers from your main controller (Alexandria_AppDelegate in my
case?)
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.
I have made the cells editable as a temporary measure because earlier
I was totally unable to get a window to open (even with the Edit
button - yeah, I'm _that_ slow :D). The idea was to make them
uneditable. Is that not the right behaviour? Should I allow the user
to edit those items (or not) and require them to click the edit
button to access the bulk of the archive ? I guess that's a usability
issue and I'm trying to shake some Linux coding habits here, so
please LART me if I'm doing wrong.
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.
Excellent - that's massively useful thank you!
Hope that helps,
That helps loads thanks!
--
Wayne Pascoe (gpg --keyserver www.co.uk.pgp.net --recv-keys 79A7C870)
You know, it's simply not true that wars never
settle anything - James Burnham
Attachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
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