2
votes

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.

3
This is a delegate method. It's worth asking: Are you double-sure your delegate is still set in IB or at runtime (and not modified at runtime behind your back)? I've been a Cocoa developer for years and I still get caught out by disconnected outlets. - Joshua Nozzi
@JoshuaNozzi Yeah I'm sure. Checked both right after the nib is brought live and in -awakeFromNib. Non-nil and pointing to the correct object. - jbrennan
Thanks, I wasted few hours because i didn't realised this is a delegate method and i separated delegate and datasource in two classes - Cristi Băluță

3 Answers

7
votes

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.

0
votes

My NSTableView is added by code instead of IB, I solved it by adding:

[tableView addTableColumn:[[NSTableColumn alloc]initWithIdentifier:@"columnIdentifier"]]
0
votes

I had the same issue after debugging for some time when I was going to delete table view and new one I found out that it was constraint doing the issue SuperView of table view had a constraint missing which was causing the whole problem.