How to remove horizontal line in bottom of section NSTableView?

27 views Asked by At

How do I delete the horizontal line between nstableview sections? These horizontal lines seem to be the lines for the start of numberofrows and the end of numberofrows.

Horizontal Lines

I have used func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? to use a custom class nstablerowview. and not calling super.draw(dirtyRect) in the override func draw() in the custom class. and it removes the horizontal lines between sections.

class CustomRowView: NSTableRowView {
    var isLastRowInSection: Bool = false // Property to indicate if the row is the last row in its section
    
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)
    }
    override func drawSeparator(in dirtyRect: NSRect) {
    }

}

now how do I remove the line while still calling super.draw, because when I don't call super, the tableview loses the highlighted selectedrow and also the alternaterow methods.

func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
        guard currentTableViewMode == .grouped else {
            return nil
        }
        let rowView = CustomRowView()
        return rowView
    }
    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
        guard let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "SiswaCell"), owner: self) as? CustomTableCellView else {
            return nil
        }
        tableView.allowsColumnReordering = true
        let (isGroupRow, sectionIndex, rowIndexInSection) = getRowInfoForRow(row)
        if currentTableViewMode == .grouped {
            // Mode "grouped"
            if isGroupRow {
                let rowView = CustomRowView()
                rowView.isLastRowInSection = isGroupRow
                // Ini adalah header kelas
                if let headerView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "HeaderView"), owner: nil) as? GroupTableCellView {
                    headerView.isGroupView = true
                    let kelasNames = ["Kelas 1", "Kelas 2", "Kelas 3", "Kelas 4", "Kelas 5", "Kelas 6", "Lulus"]
                    headerView.sectionTitle = kelasNames[sectionIndex]
}
    func numberOfRows(in tableView: NSTableView) -> Int {
        // Jumlah total baris = jumlah siswa
        if currentTableViewMode == .plain {
            return siswaData.count
        } else {
            // Jumlah total baris = jumlah siswa + jumlah header kelas
            return groupedSiswa.reduce(0) { $0 + $1.count + 1 }
        }
    }
    func tableView(_ tableView: NSTableView, numberOfRowsInSection section: Int) -> Int {
        return groupedSiswa[section].count
    }
0

There are 0 answers