Loading NSView subclasses from a Nib
Loading NSView subclasses from a Nib
- Subject: Loading NSView subclasses from a Nib
- From: James Derry <email@hidden>
- Date: Fri, 31 Jan 2003 21:52:58 -0500
Can anyone point me to some example code (or a specific thread here) that
can help me figure out how to implement a subclass of NSView from a nib
file? I want to be able to have any document-type window, pref window,
panel, etc, to be able to use this self-contained class.
I've searched the cocoa.mamasam.com archives and have come up with all kinds
of conflicting, non-working results. Specifically the "simple" example I
can't get to work is like this:
I have a TestView.nib, .h, and .m, where the nib contains a single view with
an NSTextField label that says "hello world." The "File's Owner" is set to
my "TestView" class:
TestView.h:
-----------
@interface TestView : NSView
{
IBOutlet NSView *theView; // pointing to the view in the nib, which
// is the view with the label that says
// hello world.
}
@end
TestView.m:
-----------
#import "TestView.h"
@implementation TestView
- (id)initWithFrame:(NSRect)frameRect {
[super initWithFrame:frameRect];
if (! [NSBundle loadNibNamed:@"TestView" owner:self])
NSLog(@"Loading TestView.nib failed");
return self;
}
/*- (void)drawRect:(NSRect)rect
{
}
*/
@end
In the MainMenu.nib main Window, I dragged a CustomView, and changed it to
custom class "TestView."
So, when I run the program, here's what I think should happen: the
MainMenu.nib loads, which has a TestView class which should be
"initWithFramed" which loads the nib which shows my custom view. This
doesn't work, so I'm missing something.
Okay, note that drawRect is commented out, and I know a view is supposed to
draw itself here. But I loaded a nib -- so how do I make the view draw
itself from the stuff in the nib?
ANY clues or pointers would be most welcome!
Oh, and once I get this working, it's going to be a lot more than a "hello
world" label -- I pretty much plan to have a lot of self-contained stuff
going on in there in the custom view. Maybe that's the problem and I'm
taking the wrong approach to writing this "custom component."
THANKS
--Jim (me)
_______________________________________________
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.