Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / May 2007



Tip: Looking for answers? Try searching our database.

controllers in separate nibs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wizumwalt@gmail.com - 24 May 2007 04:54 GMT
I have an action inside ControllerA that needs to make a call to
another controller, but both controllers are in separate nibs. I
understand how if they are in the same nib, but not separate nibs.

@interface ControllerA : NSObject
{
    GraphController *graphController;
}

- (IBAction)displayGraphs:(id)sender
{
    if (!graphController) {
        graphController = [[GraphController alloc] init];
    }

    [graphController showWindow:self];
}
David Phillip Oster - 24 May 2007 05:06 GMT
> I have an action inside ControllerA that needs to make a call to
> another controller, but both controllers are in separate nibs. I
[quoted text clipped - 13 lines]
>     [graphController showWindow:self];
> }

Google is your friend. Start your search here:

http://www.cocoadev.com/index.pl?MakingNibsTalkToEachOther
Wizumwalt@gmail.com - 25 May 2007 02:40 GMT
Well, I read that and I'm still not sure how to do this but here's
what I got from it.

I have objects stored in two different nibs that I'd like to
communicate to each other. So as I understand it, I need there to be
an object that exists independently of the nibs that both nibs can
refer to. This should be the files owner.

So here's where I'm confused. How do I make this happen in interface
builder. I have a toolbar button that sends an action to my graph
controller, yet my graph controller is an empty pointer in Nib A
because I don't know how to make the action go from here to an NSPanel
(which is my graph window) in Nib B.

        [toolbarItem setTarget:graphController];
        [toolbarItem setAction:@selector(displayGraphs:)];

The controller with the toolbar just declares graphController as a
pointer, but that's it so of course the icon id disabled because it's
nil.

Any help much appreciated.
David Phillip Oster - 25 May 2007 06:38 GMT
> Well, I read that and I'm still not sure how to do this but here's
> what I got from it.
[quoted text clipped - 18 lines]
>
> Any help much appreciated.

According to:
file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Conceptual/ActionMessages/Concepts/TargetsAndActions.html

if you set the action to nil, the NSApplication will search the
responder chain looking for an object to deliver the message tom
just as if you had a menu item that sent displayGraphs: to the
first responder.
Patrick Machielse - 25 May 2007 10:46 GMT
> > I have objects stored in two different nibs that I'd like to
> > communicate to each other. So as I understand it, I need there to be
[quoted text clipped - 5 lines]
> l/ActionMessages/Concepts/TargetsAndActions.html if you set the action to
> nil, the [message will be delivered] to the first responder.

That should read 'send the action to nil', so the _target_ should be set
to nil ;-)

@Wizumwalt:
There are several ways to connect actions.

- To the file's owner: set its class in IB and you can control drag a
connection from your control to any custom actions the file's owner
defines.

- 'Nil targeted actions' / First responder: in the IB inspector for the
first responder you can add your own action methods. The receiver will
be determined at runtime, like the document above outlines. This is
useful if more than one object in your nib could be the target of your
action (f.i. 'copy:') or if you want to send an action on an object that
is in the responder chain, but to which you have no reference in your
nib file.

- Refer to a singleton object outside the nib directly:
[toolbarItem setTarget:[NSApp delegate]];

patrick
David Phillip Oster - 25 May 2007 15:03 GMT
> > > I have objects stored in two different nibs that I'd like to
> > > communicate to each other. So as I understand it, I need there to be
[quoted text clipped - 8 lines]
> That should read 'send the action to nil', so the _target_ should be set
> to nil ;-)

Thanks for the correction. Yes, of course I was trying to say: set the
target to nil, and the action is sent up the responder chain.

> @Wizumwalt:
> There are several ways to connect actions.
[quoted text clipped - 15 lines]
>
> patrick
Wizumwalt@gmail.com - 28 May 2007 21:41 GMT
> - 'Nil targeted actions' / First responder: in the IB inspector for the
> first responder you can add your own action methods. The receiver will
[quoted text clipped - 3 lines]
> is in the responder chain, but to which you have no reference in your
> nib file.

I'm trying to do this option here and I've been looking at this
howto ... http://www.cocoadev.com/index.pl?MenusAndDocuments ... I'm
trying to get a menu item talk to an action of a controller that is in
a separate nib file.

So I clicked on the first responder icon and added the action to my
main menu nib.

Then I connected the menu items to the first responder of the menu nib
and made the connections there. I have the action methods in a
controller which is in the MyDocument.nib, but when I run this, things
still aren't working.

I'm not sure what I'm doing wrong.
David Phillip Oster - 29 May 2007 01:47 GMT
> Then I connected the menu items to the first responder of the menu nib
> and made the connections there. I have the action methods in a
> controller which is in the MyDocument.nib, but when I run this, things
> still aren't working.

BY default, controllers aren't subclasses of NSResponder and aren't in
the responder chain. See: http://www.borkware.com/quickies/single?id=214
Michael Ash - 29 May 2007 04:21 GMT
>> Then I connected the menu items to the first responder of the menu nib
>> and made the connections there. I have the action methods in a
[quoted text clipped - 3 lines]
> BY default, controllers aren't subclasses of NSResponder and aren't in
> the responder chain. See: http://www.borkware.com/quickies/single?id=214

A much easier, although somewhat more limited, approach is to simply make
your controller be the delegate of your NSWindow instance. As the delegate
does not actually become part of the responder chain there is no need to
subclass NSResponder and there's no need to manually insert anything, but
you still get to handle any action messages that weren't handled by
anything in the window.

For more information on what gets sent where, see:

http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArc
hitecture/chapter_2_section_6.html


Signature

Michael Ash
Rogue Amoeba Software

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.