Hi,

I'm running X-Code 3.1.3 on OS X 10.5.7, Intel Macbook. As a means of getting the hang of Cocoa, and having some fun at the same time, I've been building a simple Desktop Twitter Client.

I've previously worked through Hillegass' excellent Cocoa book. Building on his example of using Amazon XML Data, I've managed to download the status update XML from Twitter and have it displaying in an NSTableView, using my AppController class to parse the XML as a data source. This works a treat, but as different Tweets are of different lengths, I wanted to implement variable row heights.

I've made my AppController class a delegate of the NSTableView (it is also acting as the Data Source), and implemented the tableView:heightOfRow: delegate method as follows:

- (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;
}

Note that I've already set Wrap etc in Interface Builder. This works, but suffers from a fair amount of graphical corruption. Each row appears to draw itself with the correct height, but if one row is particularly tall the next row down is prone to overlap slightly, as if it's origin is not being updated by the increased height of the previous row. This results in text collision.

Best illustrated with a picture: http://twitpic.com/9fzeq

The issue here is not that the row height is too low - if I set tableView:heightOfRow: to return a constant, deliberately too low value (48.0 in this example), then the cell contents are simply truncated and no text collision occurs.

Picture of this: http://twitpic.com/9fzqy

Further experimentation with tableView:heightOfRow: shows that provided the value returned is constant, it has no problem tiling the rows, but if the value varies (I wrote a toy program randomly generating row heights in the range 48..80), then this kind of collision occurs. Given as the whole point in this method is to support differing row heights, I find this a bit odd.

So, am I doing something obviously wrong, or is this a problem with Cocoa itself?

Cheers in advance,

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