In the beginning there was NSTableView. It was NSCell-based, and we just had to live with that. The table held a prototype cell, and copied it each time it was needed, asking the data source to supply an object value for it on-demand. The delegate could step in to customise the cell further, even managing multiple different cell classes if it needed.
OS X 10.5 brought us NSCollectionView and IKImageBrowserView. The image browser made some sense as a fairly specialised view class, but you could fairly quickly hit its limits. We initially could only supply data to it, without having access to the cells that were ultimately used to get things onscreen.
And NSCollectionView was a very strange beast in many ways. No data source! Instead we supplied a full array of model objects, little controllers were created for them, and then the corresponding views laid out in a neat grid fashion.
Shortly after we got our hands on UITableView and it was a bit of a revelation. There was nothing like the quirky NSCell of old; it was all view-based now! In most respects UITableViewDataSource is very clear-cut in dealing purely in terms of data, and not the actual presentation of that. But one method has always struck me as a slightly odd exception:
- (UITableViewCell *)tableView:(UITableView *)tableView
This is the one time the data source (as opposed to the delegate) gets involved in the presentation layer, and has to create and configure a view for displaying the data. This has always struck me as a little odd (although I’m not too sure what else Apple could have done here).
So it’s interesting to wind forward to OS X 10.7, where NSTableView gained support for being view-based, and note that NSTableViewDelegate is the one responsible for creating and setting up cell views for display. As a result, for many use cases, despite being a delegate method it’s required to be implemented. Perhaps we’re trading off one oddity for another :-)
Similarly, 10.11 is effectively porting UICollectionView’s design across to OS X, by updating NSCollectionView. And Apple look to be keeping the design of having the data source be responsible.
So. After all that, is NSTableView the freak among the crowd, or our one true shining example?