Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide NSTableView gridlines / seperators for empty items

I have a large NSTableView with only a few items, which are separated by gridlines / separators. All is great apart from the fact that, below the items, are a bunch of gridlines, for empty items. How is it possible to show gridlines for items that exist, but to just have plain background for non existent items?

Note: UITableView has a way to set a footerView - this same method is not possible with NSTableView, otherwise it would just be a case of setting a big empty view as the footer...

like image 847
James Alvarez Avatar asked Nov 06 '25 17:11

James Alvarez


1 Answers

I have figured out one way:

In interface builder, set the 'row height' of the tableview to a very large number i.e. 10000, and make it 'Fixed'. In the delegate implement the tableView:heightOfRow:

e.g. in swift:

func tableView(tableView: NSTableView!, heightOfRow row: Int) -> CGFloat {
        return 50
}

This means that cells that don't have content are so big that you can't see the gridlines, as the above method seems to only get called for existing cells.

The other way as per Elwisz' comment, is to implement drawBackgroundInRect: of NSTableRowView.

like image 134
James Alvarez Avatar answered Nov 09 '25 10:11

James Alvarez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!