• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Loading NSView subclasses from a Nib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: including library in .app
  • Next by Date: Re: menu outlet in IB doesn't work for some views/controls?
  • Previous by thread: Re: menu outlet in IB doesn't work for some views/controls?
  • Next by thread: Determining if images are roughly equal
  • Index(es):
    • Date
    • Thread