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: 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