Re: NSTableView row height calculation
Re: NSTableView row height calculation
- Subject: Re: NSTableView row height calculation
- From: Keith Blount <email@hidden>
- Date: Sat, 25 Jun 2005 13:18:12 -0700 (PDT)
Hello,
Thanks for sharing the changed code. I tried it out,
but I got drawing glitches with column resizing using
this. Have you tried resizing the table columns when
you have only one or two items in the view (ie. with
lots of blank space beneath)? If you make the column
smaller so that the rows get higher, everything is
fine. But if you then make the column wider so that
the row gets shorter, the bottom part of the table
view (ie. where the bottom part of the row was before
resizing) doesn't redraw, meaning that you get the
bottom line repeated over and over (hope that makes
sense). This is why I went the route of storing the
table column widths in my own version, to avoid this.
The trouble is, there is no method that tells you (as
far as I know) that a column is in the middle of a
live resize - if there was, you could just force a
redraw. I could be wrong, though.
> When using binding with a tableview, is there a way
> (from the
> tableview's perspective) to query the values for the
> columns and rows ?
> (I know how to do this for NSTableDataSource.)
> If there is such a way then a tableview sub-class
> could be written to
> provide a general solution for variable row heights.
You could take a look at the RowResizableTableView
class for this. You could call [[self dataSource]
tableView:self objectValueForTableColumn:col row:row],
for instance. That would necessitate implementing this
method in the datasource even if you are using
bindings, but that should work fine - this is
certainly how RowResizableTableView does it, and I
have got that to work with bindings in the past.
Hope that helps.
All the best,
Keith
--- Steven Spencer <email@hidden> wrote:
> Hi Keith,
>
> Thanks for you're reply, it gave a me an idea :
> I'm now caching the row heights in a document-level
> mutable
> dictionary, dct.
> (An array might be OK too, if it's resized when the
> number of table
> rows changes.)
> The row heights are calculated only when required
> and stored in the
> dictionary.
> This also avoids the display glitch when resizing
> the columns.
>
> - (float)tableView:(NSTableView *)tableView
> heightOfRow:(int)row
> {
> NSString *key = [NSString stringWithFormat:@"%i",
> row];
> NSNumber *height;
>
> if (!(height = [dct objectForKey:key])) {
> //calculate new row height
> NSString *str = [[[myController
> arrangedObjects]
> objectAtIndex:row] target];
> NSTableColumn *col = [[myTableView
> tableColumns] objectAtIndex:0];
>
> NSCell *xCell = [col dataCellForRow:row];
> [xCell setObjectValue:str];
> [xCell setWraps:YES];
>
> height = [NSNumber numberWithFloat:[xCell
> cellSizeForBounds:NSMakeRect(0.0, 0.0, [col width],
> FLT_MAX)].height];
> [dct setObject:height forKey:key];
> }
>
> return [height floatValue];
> }
>
> - (void)tableViewColumnDidResize:(NSNotification
> *)aNotification
> {
> [dct removeAllObjects];
> [myTableView
> noteHeightOfRowsWithIndexesChanged:[NSIndexSet
> indexSetWithIndexesInRange:NSMakeRange(0,
> [myTableView numberOfRows]
> - 1)]];
> }
>
> - (void)tableView:(NSTableView *)tableView
> didClickTableColumn:
> (NSTableColumn *)tableColumn
> {
> [dct removeAllObjects];
> [myTableView
> noteHeightOfRowsWithIndexesChanged:[NSIndexSet
> indexSetWithIndexesInRange:NSMakeRange(0,
> [myTableView numberOfRows]
> - 1)]];
> }
>
> When using an array controller, I've found it
> necessary to add the
> following code because array returned by the
> arrangedobjects method is empty until the nib has
> loaded and the
> heightOfRow delegate method is called before the nib
> has loaded.
>
> -
> (void)windowControllerDidLoadNib:(NSWindowController
> *) aController
> {
> [super windowControllerDidLoadNib:aController];
>
> // Add any code here that needs to be executed
> once the
> windowController has loaded the document's window.
> [dct removeAllObjects];
> [myTableView
> noteHeightOfRowsWithIndexesChanged:[NSIndexSet
> indexSetWithIndexesInRange:NSMakeRange(0,
> [myTableView numberOfRows]
> - 1)]];
> }
>
> When using binding with a tableview, is there a way
> (from the
> tableview's perspective) to query the values for the
> columns and rows ?
> (I know how to do this for NSTableDataSource.)
> If there is such a way then a tableview sub-class
> could be written to
> provide a general solution for variable row heights.
>
> - Steve Spencer
>
>
>
> On 24 Jun 2005, at 18:07, Keith Blount wrote:
>
> > Hello,
> > ......
> >
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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