• 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
Re: Loading a custom view and its subviews from a nib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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/


References: 
 >Loading a custom view and its subviews from a nib (From: Robert Miller <email@hidden>)

  • Prev by Date: MemoryMapping Large Files - ???
  • Next by Date: function keys
  • Previous by thread: Re: Loading a custom view and its subviews from a nib
  • Next by thread: Re: Loading a custom view and its subviews from a nib
  • Index(es):
    • Date
    • Thread