What's the NSView version of NSTableView -noteNumberOfRowsChanged?
Asked Answered
S

2

7

The NSTableView -noteNumberOfRowsChanged documentation says:

Note: When using NSView-based table views this method should be avoided. The table will query the data source for the new number of rows, and properly insert (or remove) rows at the end of the table as necessary with an animation.

Unfortunately, it doesn't say what I should use instead!

I've changed my app from an NSCell-based table to an NSView-based table, in order to use (slightly) more sophisticated custom cells (which are supposedly easier to design/draw as NSViews), but I'm seeing significant performance issues, even on small tables.

I'm already calling -reloadDataForRowIndexes:columnIndexes:, and empirically that is insufficient to get it to re-query -numberOfRowsInTableView (and it gives a range exception trying to draw a row greater than the previously reported number of rows).

Is there a method I should be calling? Or are NSView-based tables simply not meant for performance-critical tables which will frequently have rows added to them?

Strahan answered 2/4, 2014 at 16:48 Comment(3)
View based table can be used keeping the performance high. Provide more information or paste the code for your data source and delegate method.Smattering
aneesh171: I'll try to throw together a sample project later, but even apart from performance considerations, what should I be calling? Apple's API specifically says not to use this method, and I see no other method that does anything similar.Strahan
If you want the delegate/datasource methods to get called, then you can call reloadData, it will call the methods to reload all the visible rows. When you scroll then delegate/datasource method will be called for the rows which are now become visible. The best way to understand this is to put some NSLog(or whatever class you are using to log messages) in these methods.Smattering
F
3

Actually,I am still using func noteNumberOfRowsChanged() with NSView-based tableview, it acts perfectly as planned. Without using this method,NSView-based tableview is broken. NSTableView sucks, and its documentation too.

This is how I am using this method for NSView-based NSTableView:

self.pTableView.noteNumberOfRowsChanged()
self.pTableView.reloadData(forRowIndexes: set, columnIndexes: IndexSet.init(integer: 0))
Floppy answered 14/7, 2018 at 14:33 Comment(1)
I agree that NSTableView is broken without this method. There's no way to perform partial insert/remove/reload without (very problematic) animations and keeping selections if I don't have this method.Cowardice
C
0

If I exclude noteNumberOfRowsChanged, the only thing remains is reloadData.

But that is not recommended because it forces to re-create all cell views, therefore performance will be deceased.

Cowardice answered 3/10, 2018 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.