Re: Loading a custom view and its subviews from a nib
Re: Loading a custom view and its subviews from a nib
- Subject: Re: Loading a custom view and its subviews from a nib
- From: Markus Hitter <email@hidden>
- Date: Sat, 12 Jan 2002 13:20:36 +0100
Am Freitag den, 11. Januar 2002, um 16:39, schrieb Robert Miller:
Hello,
This is probably a basic question but I've had no l uck solving the
problem. I have a custom view instantiated in my nib file. The view
contains other subviews such as buttons, etc. I want to be able to load
this custom view programatically and then install it as a subview of
some other view.
- Create a NIB with your subviews, change File's Owner to your
custom class.
- Add an outlet to File's Owner, connect it to your view.
- Create Files for your custom class, add a -(id)init (or some
other init) method. In the -init method add:
if (! [NSBundle loadNibWithName:@"CustomClass" owner:self]) {
NSLog(@"Loading CustomClass.nib failed");
}
- To create an instance of you custom class, simply call:
[[CustomClass alloc] init];
This will create an instance and load the NIB in the init method.
If your custom class is a subclass of NSView, you should be able
to connect "self" of your custom class to the superview, but I'm
not sure here. This should even make the mentioned outlet
obsolete, but I didn't try it yet. It took me several hours to
figure the above.
As always in Cocoa: Once you know it: it's easy, it's logical,
it's genius.
Have fun,
Markus
- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/