NSTableView declares this optional delegate method:
- (CGFloat)tableView:(NSTableView *)tableView sizeToFitWidthOfColumn:(NSInteger)column;
Implementing it is easy, but when your table is filled with thousands of entries, you start to see performance issues, and calling this method makes the app unresponsive.
Here is what the documentation states regarding implementing the method:
Implement this method if you want to control how wide a column is made when the user double clicks on the resize divider. By default, NSTableView iterates every row in the table, accesses a cell via preparedCellAtRow:column:, and requests the "cellSize" to find the appropriate largest width to use.
For large row counts, a monte carlo simulation is done instead of interating every row. For performance and accurate results, it is recommended that this method is implemented when using large tables.
So i began crawling the web, searching for "Monte Carlo Simulations".
I now have a brief understanding of what a Monte-Carlo simulation is, but i don't understand how it can apply to this particular problem.
I mean, the max content size is something totally random. It won't follow any equation or rule, it's solely based on the content that will be inserted into the cells, so how does a Monte-Carlo method apply here, how will it help me find the adequate content size ?