Re: NSCell with Embedded NSView
Re: NSCell with Embedded NSView
- Subject: Re: NSCell with Embedded NSView
- From: Mike Rossetti <email@hidden>
- Date: Tue, 11 Apr 2006 15:46:08 -0600
Thanks and a tip of the hat to Mike Abdullah for his advice.
Here is what I ended up doing:
1. In my main enclosing view's controller, serving as a delegate to
the NSTableView:
a. maintain a cache of subviews that will be drawn within the
visible cells
b. in response to willDisplayCell allocate one of those subviews
and assign it to the target cell, sets its data source, which then
attaches the subview to the tableview and positions it where the cell
should be displayed.
2. In the NSTableView's DrawRect: before calling the super DrawRect,
detach all subviews from the table view and mark them as available.
This works fine. I get all the benefits of having a view to work
with. The performance is adequate. Bindings even work.
Initially, I tried just recreating the views on each draw pass but
that _did_ have an negative impact on performance--caching was
important.
Mike
On Apr 6, 2006, at 1:25 PM, Mike Abdullah wrote:
By floating, I assume you mean that you are trying to have a single
NSView instance that is used to draw each row. This is how NSCell
works, but NSViews are totally different. You must have an NSView
for each row.
Presumably you have an array of data that you are representing with
the items in your tableview. What you need to do is set it so that
each overall table data item is set as the objectValue of your
cell. Then, when your cell is asked to draw itself, it can request
the view needed from its objectValue and position it accordingly.
I can see why you're worried about the overhead present for "tens
of thousands of subviews." I'm afraid what this comes down to is
that if you are displaying that quantity of data in a tableview,
you simply cannot use an NSView as a cell. You need to seriously
rethink how this is going to work and either use a normal style of
tableview, or a custom NSCell that contains other cells and no views.
Also, bear in mind that you won't simply have one subview for each
row of the table. You will have one for each row, and one for
every single control that is contained in that view.
Mike.
On 6 Apr 2006, at 16:41PM, Mike Rossetti wrote:
Folks,
I'd appreciate any hints and suggestions about how to properly
draw an NSView within an NSCell in an NSTableView. I _almost_
have it working. The problem I am struggling with is that only
the cell in the very last row is being drawn properly. The crux
of the matter is that I am trying to use a 'floating' view for
rendering the contents of each cell in the single column in the
table. (I need to use this view because the data being shown is
complex and does not lend itself to composition in columns: it's a
two-line presentation where both lines do not line up column-wise.)
The floating view approach saves having to have, potentially, tens
of thousands of subviews, one for each row. Unfortunately, trying
to draw the view in the cell's drawWithFrame:
[snip]
What is the recommended way to draw a floating NSView in response
to a NSCell being redrawn?
Thanks,
Mike
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden