1

I'm trying to make a simple view-based NSTableView with groups and regular cells. Every cell is drawn correct and shows everything I need unless I add this method to my NSTableViewDelegate/DataSource:

func tableView(tableView: NSTableView, isGroupRow row: Int) -> Bool {
    return (tableContent[row] as NSDictionary)["group"] != nil
}

It works just fine, but cells that become group cells show nothing. I've tried it on different cell types, but still nothing, just a semi-transparent gray background. Even if I add something like

override func drawRect(dirtyRect: NSRect) {
    NSColor(calibratedRed: 0, green: 255, blue: 0, alpha: 1).setFill()
    NSRectFill(dirtyRect)
    super.drawRect(dirtyRect)

    // Drawing code here.
}

to my group cell class I'll get only a semi-transparent gray background.

Andrii Liakh
  • 619
  • 3
  • 16

1 Answers1

1

I think maybe you make the same mistake as I did today.

When using func tableView(tableView: NSTableView, isGroupRow row: Int) -> Bool, the func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? no longer provides tableColumn for grouped rows, which means tableColumn is nil. So if you implementation relies on tableColumn.identifier, it is unreliable.

You should change your implementation to relying on row with grouped rows.

Owen Zhao
  • 3,205
  • 1
  • 26
  • 43