Update cell content in a view based tableView

I have a viewbased tableView ;

- Some cells are group headers (defined in tableView(tableView: NSTableView, isGroupRow row: Int) -> Bool)

- I want to update the content of the text of these group cells when I add an item in the group.


My problem is that the update of the label is out of my control: it occurs only when tableView has to reload the cvell (after scrolling for instance), in tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView?


Is there a way to force the update of these cells (each time count of cells change for instance) ?

If you want to push changes to the table, use one of the "reload…" methods. If you want the table to pull changes, use bindings to connect the cell view contents to KVO-compliant properties of the underlying data model.


In the specific case of the number of rows changing, though, use noteNumberOfRows changed.


Note that it's generally not useful to cause an update (i.e. redraw), because you don't know exactly what information the table view has (short-term) cached, and what it will fetch from its data source. Instead, you tell it that its underlying data has changed. The idea is to be as specific as possible, to give the table view opportunities to perform as well as possible.

Thanks.


I tried


self.tableView.reloadDataForRowIndexes(NSIndexSet(index: groupRow), columnIndexes: NSIndexSet(index: 0))


where groupRow is the computed row for the group label (which I tested is OK)


But probably, tableCell is fetched from cache (if I scroll far enough, the label gets updated); how can I flush the cache ?

You did flush the cache, for that groupRow/column 0 combination. Now you have to debug your code to find out what's wrong with it. You will likely need to enlarge your scope of investigation beyond a single line of code.


Note that the answer is not that 'reloadData…' doesn't work. Table view APIs are well-established, and so central to Mac apps that they are effectively field-tested millions of times a day.

Thanks, important to know that the cache is flushed. I'll investigate further. In fact, I didn't suspect reload not to work (just my code does not make it work properly).

There could well be a bug or at least an undocumented behavior.


The problem seems to be because it is a group item ; I have replaced, for test purpose, groupRow by groupRow+1 in


self.tableView.reloadDataForRowIndexes(NSIndexSet(index: groupRow), columnIndexes: NSIndexSet(index: 0))


and it updates immediately.


I looked in forums and found on stackoverflow someone with same issue :


here is the thread : questions/27999317/nsoutlineview-reloaddataforrowindexes-not-updating-swift/35266361#35266361

If I replace


self.tableView.reloadDataForRowIndexes(NSIndexSet(index: groupRow), columnIndexes: NSIndexSet(index: 0))


by


self.tableView.reloadData()


it works fine.

It's definitely a bug. I've reported it. Please do too and maybe it will be fixed.

Update cell content in a view based tableView
 
 
Q