'NSTableCellView not displaying its stringValue
The cells themselves appear with the amount of items in the items array (I can select them), but they don't have the title assigned to them.
...
let items: Array<String>? = // contains only strings (also without control characters)
@IBOutlet weak var tableView: NSTableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
func numberOfRows(in tableView: NSTableView) -> Int {
return self.items!.count
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if let cell = tableView.makeView(withIdentifier: tableColumn!.identifier, owner: self) as? NSTableCellView {
cell.textField?.stringValue = self.items![row]
return cell
}
return nil
}
...
Solution 1:[1]
For some reason I had to select the table view on the view hierarchy and set the content mode to cell based and back to view based. Now it works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexandra |
