NSTableBackgroundView

226 views Asked by At

I have a ViewController which has a single TableView within its content. Within the ViewController I access the actual Table via:

NSView * myView = self.view.subviews[0];
myView = myView.subviews[0];
NSTableView *myTable = myView.subviews[0];
[self.targets sortUsingDescriptors: [myTable sortDescriptors]];
[myTable reloadData];

This actually is clumsy but seems to work. Except that when I mouse down within the table when the vertical scroll bars are active. Then, I raise an exception because in the final line of accessing subviews to reach myTable, the subview array has several NSTableBackgroundViews before the actual TableView that I created and want to access.

NSTableBackgroundView apparently is not documented and does not have a sortDescriptors method (hence the exception).

Perhaps someone can point out a better way to get to the table which is more reliable, or can someone say whether enumerating the final subview array to find the desired ClassOf NSTableView is safe?

Many Thanks!

1

There are 1 answers

0
BlueskyMed On

in lieu of any other answers, I implemented planB, I took the array of subviews and enumerated on them to find the actual NSTableView. This seems to work when I bang on the UI to test it and no more flags are raised.

I wish there were a cleaner way I could discover to get the view I want without traversing all the subviews.