Re: tables cells and views
Re: tables cells and views
- Subject: Re: tables cells and views
- From: Andy Lee <email@hidden>
- Date: Sun, 28 Apr 2002 12:33:12 -0400
At 5:20 PM +0200 4/28/02, nicolas berloquin wrote:
let's say I want to show a list of thumnails with a filename, and
a couple of buttons underneath each thumbnail,
could someone tell me if I really can't design one copy of this as
a custom view in a NIB file, then
set it as a cell basis inside a matrix ?
You mentioned wanting know-how, but sometimes it helps to have a
little "know-why" as well:
There is a reason cells aren't views. As the NSCell doc says, "The
NSCell class provides a mechanism for displaying text or images in an
NSView without the overhead of a full NSView subclass." For example,
if you had a list containing hundreds of items, it would be expensive
to implement it with hundreds of subviews. Prohibitively expensive?
I don't know. In the NEXTSTEP days, the cost of one graphics context
per view was apparently important enough to warrant the introduction
of the cell concept.
I don't know if there are other, non-performance-related reasons for
NSCells. For example, at runtime you can change the cell a view
uses. That doesn't seem like a compelling benefit offhand, but maybe
I'm overlooking something. Another thought: in a list, you typically
want the list view to control the layout of its items. It would not
make sense for a cell to have a -setFrame: method, such as it would
inherit if if were an NSView.
Anyway, NSMatrix is an NSControl, and as such is based on NSCells.
This is why it doesn't give you the option to specify an NSView as
the thing it contains repeated instances of, although you, coming new
to Cocoa, might have expected this to be natural.
If you just want a list view that uses subviews instead of cells, you
can create it yourself. (Hint: -addSubview and
-removeFromSuperview.) You'll have to write your own logic to manage
the layout of the subviews, but that should be a straightforward
exercise. You might see a cost in performance, but maybe not.
So [Ondra's] advice is to create a nscell subclass and have its
render method draw an nsview ?
sounds reasonable
You mentioned wanting buttons within each cell, so it's not just a
matter of rendering. You also want the buttons to behave properly in
response to clicks and drags.
, it would have been nice if cocoa had let us do this directly...
You might want to submit your wish to Apple in a bug report
<
http://bugreport.apple.com>. Questions on specializing NSCell
behavior appear again and again on these mailing lists. Maybe Apple
could add something to Cocoa (if only more documentation and/or
examples) to make this simpler or more obvious.
(are all lists only text or simple images ?)
No, but very many are. NSCell provides a lightweight mechanism for
these extremely common cases. Meanwhile, it is completely possible
in Cocoa to achieve what you want, though not as trivially as you
might have liked.
--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.