2

I'm trying to size the rows of a NSTableView to exactly 9 rows fit. I've tried [menuTableView setRowHeight:floor(menuRect.size.height / 9)]; and I've tried [menuTableView setRowHeight:(menuRect.size.height / 9)]; and [menuTableView setRowHeight:ceil(menuRect.size.height / 9)]; but all of them have the same issue, if I've selected row 0 then row 9 is clipped at the bottom and if I select row 9 then row 0 is clipped at the top.

How can I set up a NSTableView to show 9 full rows so no matter what there is never a partial row visible?

Thanks,

edit: Yes menuRect is the frame for the menuTableView

edit:

Below is the full method I use to position the NSTableView and set the row height I've tried to remove any rounding issues with the use of the rowHeight variable. You can see with the attached screen shot that the last row isn't fully displayed

- (void) updateGUIPositions
{
    NSRect screenRect = [self frame];
    NSRect menuRect;

    // Set the menu location on screen
    NSInteger spacer =  screenRect.size.width / 9;
    menuRect.size.width = floor(screenRect.size.width - (spacer * 3)) / 2;
    menuRect.size.height = ceil(screenRect.size.height - (spacer * 2));
    NSInteger rowHeight = menuRect.size.height / 9;
    menuRect.size.height = rowHeight * 9;
    menuRect.origin.x = menuRect.size.width + (spacer * 2);
    menuRect.origin.y = spacer;
    [menuScrollView setFrame:menuRect];

    // Setup the row height
    [menuTableView setRowHeight:rowHeight];
}

enter image description here

Justin808
  • 20,859
  • 46
  • 160
  • 265

2 Answers2

1

I am not sure if this will work, but it sounds like a rounding error(I had the same problem with a UITableView). Try making the height of the NSTableView's frame 1px larger. So, menuTableView.frame.height = menuTableView.frame.height+1;

EDIT Try using this...

`float rowHeight = menuRect.size.height / 9.0f;`
Skyler Saleh
  • 3,961
  • 1
  • 22
  • 35
0

If you can fix the size of the rows and instead set the size of the frame programmatically, this related question suggests this formula works:

numRows * (rowHeight + intercellSpacing.height)

Using that formula, the scroller will draw, but you could just turn it off.

Community
  • 1
  • 1
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114