View based table view layout woes

Discussion in 'Mac Programming' started by Starfox, Nov 8, 2012.

  1. Starfox
    Expand Collapse
    macrumors regular

    Apr 7, 2011
    I'm working on my app that's mainly for displaying tweets, and I've been trying to get it to properly layout multiple NSTextView-s (without scroll views) inside a table cell view, and the results have been unpleasant:

    (The red rectangle is something I added so I can see the bounds of the text view - it's a debugging visual aid.)

    Expanding the window seems to fix that:

    I, however, would like to know why this is happening. My code for calculating the sizes is pretty straight forward - in the end of my viewForTableColumn:row: method I have this:

    const CGFloat BaseHeight = 20.0;
        const CGFloat Margin = 0.0;
        const CGFloat Width = self.tableView.frame.size.width;
        const CGFloat DateHeight = [dateAttributedString boundingRectWithSize:NSMakeSize(Width, 0) options:NSStringDrawingUsesLineFragmentOrigin].size.height;
        const auto NewViewHeight = [tweetAttributedString boundingRectWithSize:NSMakeSize(Width, 0) options:NSStringDrawingUsesLineFragmentOrigin].size.height;
        const CGFloat NewHeight = BaseHeight + NewViewHeight + Margin + DateHeight;
        TweetManager->items[row].row_height = NewHeight;
        [tableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:row]];
        return view;
    And my heightOfRow: is:

    - (CGFloat) tableView: (NSTableView*) TableView heightOfRow: (int) Row
        const CGFloat MinimumSize = 54.0;
        if(!TweetManager) return MinimumSize;
        const CGFloat Offset = 6.0;
        return max(TweetManager->items[Row].row_height, MinimumSize) + Offset;
    What could possibly be going wrong there? I'm stumped. Any help would be greatly appreciated.

Share This Page