Quincey - cheers, that's worked a charm. I whacked in an NSLog to check, and it was indeed calculating heights for all non-visible cells with only the placeholder text "Text Cell". I'm still unsure as to why this led to the weird tiling behaviour rather than just truncated text, but I have a working solution and I know how to avoid it in future.

New solution gets the values straight from the XML (using the same methods as the datasource bits) and avoids using hardcoded values for the column. To avoid having to faff around setting the same text attributes which have already been set in Interface Builder, I've just made a quick copy of the existing cell, getting all that for free.

- (CGFloat)tableView:(NSTableView *)tv heightOfRow:(NSInteger)row
{
        // Get column for Tweet Status
        NSTableColumn *column = [tv tableColumnWithIdentifier:@"text"];
        // Create a copy of the relevant cell - retains text attributes.
        NSCell *cell = [[column dataCellForRow:row] copyWithZone:NULL];
        // Retrieve stringvalue from XML Data
        NSXMLNode *node = [itemNodes objectAtIndex:row];
        [cell setStringValue:[self valueForPath:@"text" ofNode:node]];
// Calculate height using cellSizeForBounds, limiting it to width of column.
        // Add 10 pixels for padding.
        CGFloat height = [cell cellSizeForBounds:
                                NSMakeRect(0.0, 0.0, [column width], 
1000.0)].height+10.0;
// Profile pics are 48x48, so ensure these are fully visible with >=10px padding
        height = MAX(height,58.0);
        // Release the cell copy.
        [cell release];
        return height;
}

Worth noting that this all goes wrong again if you have autohide scrollbars enabled, as it results in the column width varying between calculation and drawing.

Solved, and I am happy.

Cheers,

Alex
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to