I am new to the Mac. I am trying to update a particular cell in NSTableView without using -reloadData
, as -reloadData
updates the whole table. I have t
If your table row is smart enough to update itself with a draw, you can do something like this. This ViewController method is responding to a NSNotification post by a source object that has updated itself.
Swift 4 code:
class ObjectChooserListViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
@IBOutlet weak var tableView: NSTableView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(objectUpdating(_:)), name: NSNotification.Name("ObjectUpdating"), object: nil)
// more stuff happening
}
@objc func objectUpdating(_ notification: NSNotification) {
guard let object = notification.object as? MyCoolObject else {return}
guard let row = ObjectManager.shared.getRow(of: object.id) else {return}
guard let cellView = tableView.view(atColumn: 0, row: row, makeIfNecessary: false) else {return}
cellView.draw(tableView.frameOfCell(atColumn: 0, row: row))
}
}