问题
I've got a View-based NSTableView
which is configured in IB to be View based. Its column identifier is set, too. As are its dataSource
and delegate
set, to the same object, which claims to conform to both in the public header. I've verified these are set after the tableView awakes from its nib.
As per the docs, I've implemented -numberOfSectionsInTableView:
and it gets called and returns a non-zero number.
However, -tableView:viewForTableColumn:row:
, much to my chagrin, does not, and I can't figure out why not.
Does anyone know why this might happen? I'm running on Mountain Lion and my deployment target is also set to be Mountain Lion.
回答1:
It' simple! The problem was, even though the tableview was added to my view hierarchy, it was clipped so it couldn't be seen. NSTableView
must do some checks to see if it's actually on screen and then only request cell views for visible rows.
Because the whole tableview was essentially "off-screen", it wouldn't request any rows.
回答2:
My NSTableView is added by code instead of IB, I solved it by adding:
[tableView addTableColumn:[[NSTableColumn alloc]initWithIdentifier:@"columnIdentifier"]]
来源:https://stackoverflow.com/questions/13076847/view-based-nstableview-viewfortablecolumnrow-not-called