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: Andy Lee <email@hidden>
- Date: Fri, 5 Apr 2002 18:00:31 -0500
At 12:02 AM +0200 4/6/02, David Remahl wrote:
>> 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...
> Since loading the view from NIB is better in a vast majority of cases, and
Apple wants to press on developers slightly to go the recommended way,
perhaps?
Well, I was mainly interested in _why_ that was the recommended way. I'm
sure there is a very good explanation, but I don't see it. Why is it better
to cause disk (or at least disk cache) access when copying stuff in memory
could have been enough?
I don't know if Apple has a reason at all, or if so, whether it's a
good one. Maybe they *will* make NSView conform to NSCopying and
just haven't gotten to it yet or haven't released it yet.
Just for grins, though, I'll toss out one possible rationale:
NSViews are relatively expensive. Setting up and switching graphics
contexts is expensive (or at least it used to be, in NEXTSTEP).
That's why there are NSCells. NSCells allow you to do repetitive
drawing of similar UI elements within a single NSView, so you don't
have to reset coordinate systems and such from cell to cell.
NSCells, not NSViews, are what you should use for making long
scrolling lists of simple, almost identical UI components.
When you have a view that's more complex than a simple list element,
it's likely to be a one-per-document kind of thing as opposed to
something you'll mass-produce, so the cost of loading nib files isn't
that noticeable.
If you insist on copying a view, you can always archive it to an
NSData and then unarchive it as many times as you want, since NSView
does conform to NSCoding. But you'll have to do this work yourself,
even though it's trivial, because Apple does not want to endorse the
usage of [myView copy].
--Andy
_______________________________________________
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.