I have the following code in a viewController:
I have used this code (similar code in other places and it works fine, however in this case the tableView Cells are not being populated. When I look at this code using debugger the line
always sets cell to nil? Since I don't see anything wrong with code I suspect there is an issue with the IB?
Any ideas how to fix or how to debug further?
Code Block extension InvoicesDetailController: NSTableViewDelegate { fileprivate enum CellIdentifiers { static let lineItemLabelCell = "lineItemLabelCell" static let lineItemDescCell = "lineItemDescCell" static let lineItemAmountCell = "lineItemAmountCell" static let lineItemQtyCell = "lineItemQtyCell" } fileprivate enum fieldIdentifiers { static let lineItemLabel = "lineItemLabel" static let lineItemDesc = "lineItemDesc" static let lineItemAmount = "lineItemAmount" static let lineItemQty = "lineItemQty" } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let currentItem = invoiceItems[row] var text: String = "" var cellIdentifier: String = "" let currentColumn = tableColumn?.identifier.rawValue if currentColumn == fieldIdentifiers.lineItemLabel { text = currentItem.lineItemLabel! cellIdentifier = CellIdentifiers.lineItemLabelCell } if currentColumn == fieldIdentifiers.lineItemDesc { text = currentItem.lineItemDesc! cellIdentifier = CellIdentifiers.lineItemDescCell } if currentColumn == fieldIdentifiers.lineItemAmount { text = currentItem.lineItemDesc! cellIdentifier = CellIdentifiers.lineItemAmountCell } if currentColumn == fieldIdentifiers.lineItemQty { text = currentItem.lineItemQty! cellIdentifier = CellIdentifiers.lineItemQtyCell } if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView { print(cell.textField?.stringValue) cell.textField?.stringValue = text print(text, cell.textField?.stringValue) return cell } return nil }
I have used this code (similar code in other places and it works fine, however in this case the tableView Cells are not being populated. When I look at this code using debugger the line
Code Block if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: self) as? NSTableCellView
always sets cell to nil? Since I don't see anything wrong with code I suspect there is an issue with the IB?
Any ideas how to fix or how to debug further?