I have the following code to display macOS tableview…
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) → NSView? {
// let currentItem = invoiceItems[row]
let currentItem = customerinvoices[row]
/// print(customerinvoices[row].invoiceNumber!)
var text: String = “”
var cellIdentifier: String = “”
tableView.backgroundColor = .gray
let currentColumn = tableColumn?.identifier.rawValue
if currentColumn == fieldIdentifiers.invoiceNumber {
text = currentItem.invoiceNumber!
cellIdentifier = CellIdentifiers.invoiceNumberCell
}
if currentColumn == fieldIdentifiers.invoiceDate {
text = currentItem.invoiceDate!
cellIdentifier = CellIdentifiers.invoiceDateCell
}
if currentColumn == fieldIdentifiers.invoiceDueDate {
text = currentItem.invoiceDueDate!
cellIdentifier = CellIdentifiers.invoiceDueDateCell
}
if currentColumn == fieldIdentifiers.invoiceTotal {
text = currentItem.invoiceTotal!
cellIdentifier = CellIdentifiers.invoiceTotalCell
}
if currentColumn == fieldIdentifiers.invoiceAmountDue {
text = currentItem.invoiceAmountDue!
cellIdentifier = CellIdentifiers.invoiceAmountDueCell
}
if currentColumn == fieldIdentifiers.invoiceAppliedAmount {
text = currentItem.invoiceAppliedAmount!
cellIdentifier = CellIdentifiers.invoiceAppliedAmountCell
}
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView {
cell.textField?.stringValue = text
return cell
}
return nil
}
I would like the amount cells to be red if they are less than zero and green for => zero. How is this down within this function?