Re: Bindings&Actions on Document-based Applications
Re: Bindings&Actions on Document-based Applications
- Subject: Re: Bindings&Actions on Document-based Applications
- From: Kris Gybels <email@hidden>
- Date: Sun, 18 Sep 2005 17:18:02 +0200
Hi Michael, all,
Thanks for your extensive reply! Yes, I think you got what I mean
correctly :) The solution you describe is similar to the one in the
only other document-based and bindings-based example I've seen so
far, i.e. by linking the menu item to a window controller which needs
to have a method which does nothing but forward the action to the
array controller.
I'm a bit disappointed that this seems to be the way to do this using
bindings. Even if those action forwarding methods are just a few
lines to implement, you still need to implement one for every other
menu item like it. I didn't expect that with the promise of cocoa
bindings being "no more useless code bloat".
Did you get this yourself from an example btw, or is there some
tutorial somewhere on cocoa bindings in document-based applications?
All the tutorials I've found were on cocoa bindings in non-document-
based applications, I'd still like to see a tutorial for the document-
based case.
Thanks for the help!
Hi.
I am pretty sure I get what you are asking, but, maybe not. But
here goes.
I don't think you can do this without writing a single line of
code. You can do it with very little code. Here is what I would do.
In your main WindowController, the one that controls the nib with
the ArrayController in it you need to write a very basic method
like this:
- (IBAction)invokeAddOnArrayController: (id)sender;
{
[myArrayController insert:sender];
}
Then load up the main nib, MainMenu.nib, in InterfaceBuilder. You
want to now add this method to the FirstResponder. You that by
selecting FirstResponder in the suit case, then selecting the
Classes tab, then shift-clicking on FirstResponder. Then in the
inspector you will be able to add an action. Click the Add button
and enter in: invokeAddOnArrayController:
Now you can go back to the Instances tab, and make a connection
from your menu item to the FirstResponder in the suitcase. Control-
drag from the menu item to the FirstResponder and select the new
action you just added.
Now when you select that menu item your action should be invoked
adding a new object to your array controller.
Hope that helps, and makes sense!
Michael.
On 18-Sep-05, at 9:49 AM, Kris Gybels wrote:
Hi all,
I have made a basic document-based application with each document
showing a table which is linked using cocoa bindings to an
NSArrayController. Now, I want the "Add new element to table" menu
item to invoke the "add:" action of NSArrayController, on the
controller for the currently active document. I have some trouble
figuring out how to do this since the main menu and the document
window/controllers are specified in two separate nibs. So can
anyone explain to me or point me to the right documentation on how
you do this in IB without writing a single line of code?
It seems like a very, very basic question, so I would be surprised
if itsn't explained somewhere already, but so far, all of the
examples I've seen of Cocoa bindings were not document-based. And
the one example I saw (unfortunately don't remember which) didn't
do it without implementing extra code (by linking the menu item to
a main application controller, which then forwarded the message to
the currently active document).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40marketcircle.com
This email sent to email@hidden
_______________________________________________
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