4
votes

I have a view-based NSTableView for which some cells have enough content that it doesn't fit. I would like to be able to have the cell automatically expand when a user hovers their cursor over the cell.

In searching for this, it seems that this is the default behavior for a cell-based NSTableView. There are even methods like shouldShowCellExpansionForTableColumn, which the doc says is for cell-based table views only. Somewhere else in the doc implies that this expansion behavior is even on by default for cell-based table views?

- (BOOL)tableView:(NSTableView *)tableView shouldShowCellExpansionForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

I get the impression that I'm missing something obvious.

Goal:

  • Be able to put multiple rows of NSTextField objects in a view-based cell (more than there is pace to handle)
  • If the content overflows, put a visual indicator into the cell
  • When the user does a tool-tip style hover on the cell, expand the view to show all the content
2
That method basically shows a tooltip. What you are looking for is not easy but involves row height adjustment and row view height as well as cell view height. On 10.9 you could look into NSStackView but regardless you are looking at managing some auto layout constraints in your cell and row view subclasses and responding to notifications. ( possibly creating your own) - uchuugaka

2 Answers

0
votes

You seem to be on the right track as this should work for cell based NSTableViews. You need to put tableView:shouldShowCellExpansionForTableColumn:row: in the tableView's delegate. You could reply YES for the column of interest.

With a view based table where you use NSTextFields these scroll, truncate or wrap but there is not an expand on hover option. It is possible to set the tooltip text to be the same as the content which might be a reasonable solution.

0
votes

Did you try to change the row height (tableView:heightOfRow:) triggered by some mouse action? You might have to reload the tableview.