views:

24

answers:

1

This is what I got so far.

- (IBAction)HUDPanelDictionaryHide:(id)sender{
    extern NSPanel HUDPanelDictionary;
     [HUDPanelDictionary close];
}

This obviously does NOT work.

The HUDPanelDictionary is declared in a separate .h and .m file for an .xib file. I need to close this panel from the other .h and .m file for another .xib file. Sorry I'm being so vague!

Any ideas??

Elijah

+1  A: 

You need to #import the header containing the declaration of HUDPanelDictionary.

For example:

#import "HUDPanelDictionary.h"

@interface MyController

- (IBAction)hideDictionaryPanel:(id)sender {
    [HUDPanelDictionary close];
}

@end

I would also name things differently, for example "DictionaryHUD" rather than "HUDPanelDictionary." "Panel" is redundant with "HUD," and you should care more about its intent than its position in the class hierarchy.

Another thing I would do is make DictionaryHUD an NSWindowController subclass, and have it expose a singleton shared instance rather than use a global variable to point to the panel itself. Then the code above would look like this:

#import "DictionaryController.h"

@interface MyController

- (IBAction)hideDictionaryPanel:(id)sender {
    [[DictionaryController sharedDictionaryController] hideDictionaryPanel:sender];
}

@end

This puts the primary responsibility for your dictionary panel/HUD on an instance of a single controller class, to which other controllers (say one that manages your main window's toolbar) can forward their interactions. You could even put the dictionary HUD window controller in the responder chain to have it automatically handle actions like -hideDictionaryPanel: so nothing needs to do that kind of forwarding.

Chris Hanson
I just did that, it still says it's undeclared.
Elijah W.
See my additional edits. I think what you really want to do is expose a separate controller to interact with, not share a global variable between the two controllers.
Chris Hanson
Ok, I'm trying that now...I'll let you know
Elijah W.
Wait, what is sharedDictionaryController?? Do I declare it??
Elijah W.
What I'm saying is that your dictionary panel should be managed by its own NSWindowController subclass. That subclass should probably be a singleton, accessed via a method with a name like `+sharedDictionaryController`.This is why it's important to learn the Model-View-Controller pattern as Cocoa follows it, along with other OOP techniques, and not just throw together code cribbed from examples.
Chris Hanson