Re: multiple nibs question
Re: multiple nibs question
- Subject: Re: multiple nibs question
- From: email@hidden
- Date: Wed, 13 Feb 2002 21:27:00 -0500
Hello.
I am not the greatest expert in cocoa, but here is how I always do
things.
In the source nib (main nib) I create an outlet of type
NSWindowController. In the target nib I create a subclass of
NSWindowController. That subclass relays all the functionality that I
need.
On awakeFromNib I load the NSWindowController subclass and save the
reference into the outlet in the main nib file. In this way you get the
connection from main nib to target nib. After you have that, you can set
the reverse connection too, if you need it.
Example:
@interface A : NSObject
{
IBOutlet NSWindowController target;
}
@end
@implementation A
- (void) awakeFromNib
{
//there is no .nib below!!!
target = [[NSWindowController alloc]
initWithWindowNibName:@"myTargetNib"];
}
@end
@interface B : NSWindowController
@end
////
The outlet can be of type B, it is probably better in that way. You will
have to import the B.h file in A.h then. Or, if you have a dependency
problem you can use NSWindowController as outlet type, or use @class B
in A.h.
I bet my boots that there is a better, more scalable design out there.
Never bothered to read, since time is valuable :(. This works for me,
although I would love to see different opinions on this topic (with
examples please :)
GL.
Nick
"Ramstein keeps you awake @ nite"
I am trying trying to implement an inspector panel for my app. I need to
connect a menu item in my main nib file to an action method in the
inspector
controller class, which is the owner of a secondary nib file. From what
I've
read and the Apple source code I've perused, there appear to be two
ways to
accomplish this. One way would be to create an instance of the inspector
controller class inside the main nib file and connect the menu items
directly to the controller instance (TextEdit does this for its find
panel).
A second way would be to create an app delegate class inside the main
nib
file, which would get the shared instance of the inspector controller
and
make the appropriate method calls (Sketch does this for its Select Arrow
Tool menu item).
There seem to advantages with each approach. The TextEdit way seems more
direct to me, but I searched the list and read that NSWindowController
subclass instances (my inspector controller is a subclass of
NSWindowController) should be created programmatically rather than in a
nib
file. The Sketch way would require the creation of an additional app
delegate class to relay the menu item functions to the inspector
controller,
and also the file may start to get unwieldy if I have multiple inspector
panels that I need to connect to.
I'm kind of stuck between the two approaches right now. Can anyone
recommend
one approach over the other? It seems kind of strange to me that the two
Apple-supplied examples would differ in their respective approaches.
Thanks
for any help you can provide.
Eric Wang
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.