Skip navigation.
 
mlRe: Loading a custom view and its subviews from a nib
FROM : Markus Hitter
DATE : Sat Jan 12 13:20:36 2002

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/


Related mailsAuthorDate
mlLoading a custom view and its subviews from a nib Robert Miller Jan 11, 16:39
mlRe: Loading a custom view and its subviews from a nib Stéphane Sudre Jan 11, 17:38
mlRe: Loading a custom view and its subviews from a nib Markus Hitter Jan 12, 13:20
mlRe: Loading a custom view and its subviews from a nib Matt Neuburg Jan 14, 20:28
mlRe: Loading a custom view and its subviews from a nib Henri Lamiraux Jan 14, 21:32
mlRe: Loading a custom view and its subviews from a nib Ondra Cada Jan 15, 00:08