Closing panel in one source file from a separate source file
This is what I got so far.
- (IBAction)HUDPanelDictionaryHide:(id)sender{
e开发者_如何学编程xtern 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
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.
精彩评论