Question

In my setup I have an NSCollectionView of volumes connected to the mac. For the NSCollectionViewItem's View I have an NSBox with an NSTableView inside listing the contents of that volume.

My problem comes when trying to add/remove items to the NSTableView. The NSBox seems to be initialised once, so there is only one NSTableView. This means that when I want to update the data inside the NSTableView I cannot call reloadData on an IBOutlet and have it update all the tables.

If I create an IBOutlet in a subclass of the NSBox, it is nil for the instance, so I cannot call it via that.

The closest I have come is by enclosing a @try @catch around the code that returns the object at a row in a column, an exception occurs because that item no longer exists, so I can grab the tableView and call reloadData, which seems to update that specific NSTableView.

The problem with this is that if the item removed is at the end of the table, or if an item is added, the exception won't occur as it can see all the existing items.

Has anyone had any experience with an NSTableView on an NSCollectionViewItem's View? How did you update the tables?

Was it helpful?

Solution

Put the NSBox (with its NSTableView) into its own nib. Each time you create a new collection view item, load the nib, set that NSBox as the collection view item's view, and release the NSBox.

As for feeding the table views, the easiest way is probably Bindings. Bind each column of the table view to a different property of the model object that the collection view item represents. You'll probably want to go through an array controller, of course, which means having one of those per collection view item, and adding them to an array, which you'll release in dealloc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top