1
votes

everyone!

How to populate first column of nstableview with strings from array and the second column with strings from another array in dependence of selection in first column?

For example, look at the iTunes window, where the first column is selected playlist, and the second, a list of songs.

I could not find something like this on the internet.

I would be very grateful for the help.

This is little info about my model:

array with content for tableView populated with instances of NSObject sublass. This instances have three properties, to properties - NSString object, and last property an NSArray object with another strings. First and second properties used to populate first column, and i don't know how to populate sec on column with third property (strings from another array).

How to do this with bindings?

1

1 Answers

1
votes

First of all: You do not populate columns, but rows. But reading your whole question, it seems to be that you understood this.

The solution is, that you do this with nested arrays and two table views:

Bindings:

A. The first table view gets the array of instances via an array controller that are on the top level of your model. Let's say "list of playlists". This array builds the rows for that table view with probably one column. The first column is bound to a property, likely "title".

playlistsArrayController.contentArray: somewhere.playlists
viewColumn.content: playlistsArrayController.arrangedObjects.title

B. Then you have a second table view with a second array controller. This is bound to the selection of the first one (playlists) and the property that contains the subentries, i. e. songs. This second array builds the rows of the second table view. Typically you have more columns there, every bound to a specific property ("title", "length", …)

songsArrayController.contentArray: playlistsArrayController.selection.songs
viewColumn1.content: songslistsArrayController.arrangedObjects.title
viewColumn2.content: songslistsArrayController.arrangedObjects.length

Both bindings are typed in Safari only for explanation.