2
votes

I'm trying to display a NSTableView inside a NSTableView. This is for an iTunes-like albums/tracks view. So there's a list of 10 albums, each album has some tracks. I want to display the albums in the outer table view and the tracks for each album in the inner.

The first NSTableView is bound to an NSArrayController. Each object in the array has its own "tracks" NSArrayController, but I can't figure out how to tell the 'tracks' NSTableView that its content comes from a property of the 'album' NSTableView.

2
Deleted my answer after fiddling with your project. I can't see how to get objectValue bindings working with an array controller embedded in a cell-- Nibs/XCode just seem to think the objectValue is the album, not the nested track cell. Tellingly, I can't nest an AC object in a cell view in IB either. My only thought is making the entire album cell a custom view Nib, and having an array controller outlet there to hook up. In the new Nib, XCode will be able to find the array controller object.stevesliva

2 Answers

2
votes

If I understand you right, the source content of the nested array controller comes from objectValue of the owner table cell. So you can't put the array controller content source to be the objectValue of the table cell. I'm doing similar in that I want to filter the array content based on the object value

What I'm doing, which seems to be working, is to make a seperate nib file for your nested table cell view, with it's own nstablecellview subclass. Include the array controller in the nib and create an outlet to it in your cell view subclass.

Register it with the table view in the viewDidLoad method of the tables view controller:

NSNib *cellView = [[NSNib alloc] initWithNibNamed:@"MyTableCellView" bundle:nil];
[myTableView registerNib:cellView forIdentifier:@"myTableCellView"];

Then, in the awakeFromNib method of your cell view subclass, manually make your bindings that require the object value:

[self.arrayController bind:@"contentSet"
                  toObject:self
               withKeyPath:@"objectValue.tracks"
                   options:nil];

Voila.

Note that when using this technique, the files Owner of the nib file is not your nstablecellview subclass, it is the view controller of the table view.

-1
votes

The problem lies in not understanding the MVC-pattern (Model-View-Controller). Content for a view never comes from another view, it comes from model objects via a controller. The content of each of your tableviews always comes from an NSObjectController, or a subclass like NSArrayController. Basically, there are two solution:

  • bind the 'tracks' tableview to the selection of the 'album' array controller
  • create a 'tracks' array controller and bind it to the selection of the 'album' array controller. Bind the 'tracks' tableview to the 'tracks' array controller

A third solution is to use an NSTreeController with an NSOutlineView but outline views and tree controllers are notoriously hard to work with.