• 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: Ondra Cada <email@hidden>
  • Date: Tue, 15 Jan 2002 00:08:33 +0100

Matt,

>>>>>> Matt Neuburg (MN) wrote at Mon, 14 Jan 2002 11:28:54 -0800:
MN> >This is probably a basic question but I've had no l uck solving the
MN> >problem. I have a custom view instantiated in my nib file. The view
MN> >contains other subviews such as buttons, etc. I want to be able to load
MN> >this custom view programatically and then install it as a subview of
MN> >some other view
MN>
MN> What I do is to group the custom view instance into a box and make an
MN> outlet to the box....

This is not needed (anymore, from 10.0 or so, when IB started to support
free views).

Just put the view into NIB, connect some outlet "newView" directly to it:

NSView *newView; // connected to the new view
NSView *oldView; // some original view, to be replaced by the new one

...
[[oldView superview] replaceSubview:oldView with:newView];
...

works like a charm. Of course, if you don't want to replace but just add,
addSubview: is there, too -- but in my experience, replacing is much more
frequent, and somewhat more complicated, so I described it ;)
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc


References: 
 >Re: Loading a custom view and its subviews from a nib (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: PB Lexical Analysis (function popup): How?
  • Next by Date: Re: Objective-C (Possibly OT)
  • Previous by thread: Re: Loading a custom view and its subviews from a nib
  • Next by thread: Re: always-on computing (Easiest way to delete a file)
  • Index(es):
    • Date
    • Thread