Re: A Nib Question: Multiple Instantiations of Views
Re: A Nib Question: Multiple Instantiations of Views
- Subject: Re: A Nib Question: Multiple Instantiations of Views
- From: David Remahl <email@hidden>
- Date: Fri, 05 Apr 2002 22:12:28 +0200
What is the justification for not having NSView conform to NSCopying? This
is an often requested function, and I can't see why it couldn't be
implemented...
/ David
>
On Thursday, April 4, 2002, at 12:16 AM, The Amazing Llama wrote:
>
>
> I have a .nib in which I define a window, Foo, and an unconnected view,
>
> Bar.
>
>
>
> Bar has widgets in it, including a button that opens and closes a tray
>
> off of Foo and some random text objects.
>
>
>
> What I want to do is instantiate multiple copies of Bar, with different
>
> text in the text objects, and pop them all into Foo so that
>
> all of them appear in a list.
>
>
The easiest way to do this is to put your view (Bar) in its own nib.
>
Then your controller code can:
>
>
> So the basic question is this: how do I
>
> - load a view from the nib so that I get the formatting information,
>
> - programmatically make lots of copies of it
>
>
Load the nib with the view multiple times.
>
>
> - programmatically change the text, and
>
>
Have outlets from your controller to the text objects in Bar, and
>
set the text on them as you load them. (The outlets will be reset to the
>
new copies of the views when you load the nib again the next time.)
>
>
Since your Bar is now in a different view than your Foo, you
>
probably have to programmatically set the target and action of the Bar
>
button which opens/closes the tray now.
>
>
> - programmatically put them all into the window?
>
>
Have a scroll view in the window (Foo) with a simple NSView inside.
>
Have an outlet to that inside view. As you load your Bars, add them as
>
subviews to that view, positioning them as you desire (presumably in a
>
column?), setting the view's bounds to fit its subviews as you do this.
>
>
The scroll view will automatically handle putting the scroller in
>
and sizing it appropriately to how much of the inside view is visible,
>
et cetera.
>
>
> Can I?
>
>
Yep. Feel free to ask for more details if this isn't enough to get
>
you started.
>
>
Hope this helps,
>
--Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.