On Jul 5, 2009, at 17:06, Alex Holland wrote:

- (CGFloat)tableView:(NSTableView *)tv heightOfRow:(NSInteger)row
{
        // Get second column (index 1 - status text)
        // (first column, index 0,  is Twitter profile pic)
        NSTableColumn *column = [[tv tableColumns] objectAtIndex:1];
        // Get text cell from second column for row
        NSCell *cell = [column dataCellForRow:row];
// Calculate height using cellSizeForBounds, limiting it to width of column.
        // Adding 10 pixels for padding.
        float height = [cell cellSizeForBounds:
                                                NSMakeRect(0.0, 0.0, [column 
width], 1000.0)].height+10.0;
// Profile pics are 48x48, so ensure size is at least 58px to allow some padding
        height = MAX(height,58.0);
        return height;
}

You're assuming that the cell has the current text, but it doesn't. (It would be far too inefficient to set the cell to the row's data before every call to tableView:heightOfRow:. It only gets set to the correct data for the row just before being drawn.)

Instead, you should find the text directly from your data model (using 'row'), measure it in some way that doesn't mess with the table view's internals (i.e. modifying its data cell is probably not a good idea, although I don't really know), and return the height from the that measurement. Note that this is likely to be kind of slow, in general, relative to the frequency with which this delegate method is called, so in a real app you'd probably consider caching the computed heights somehow.

The other thing wrong here (speaking from memory -- I haven't checked the documentation on this recently) is that it's generally a no-no to hard code column indexes. However, if you're getting the text from your data model anyway, you won't need the column at all.


_______________________________________________

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