Search code examples
objective-ccocoaswiftnstableview

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...


Solution

  • 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.