Take the 2-minute tour ×

Does it make sense logically to have two data sources populating a single NSTableView? Or would a pop up button (with ability to choose from which data source to read)be more reasonable?

If I go with the single NSTableView option, would I be better off if I input all the data into a single data source (say an NSDictionary) and then populating the table? The only problem that I see with this idea is what happens when a selection of the table is done.. How would I decipher which of the original location was selected.

Another idea/potential problem that just popped into my head ... if I take the data from the data source and populate the table directly, how would give the count of the table in the relevant NSTableView 'count' method.. Would adding the count of data store 1 and data store 2 do it?

Sorry if it's a bit jumbled up.. Thanks for any input!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You can definitely use multiple data sources for the data to be displayed in the table view, but they must all be funnelled through a single controller object that is assigned as the table view's datasource and which implements the NSTableViewDatasource protocol.

You will have to write some code in your controller object so that you keep track of the multiple source arrays that make up and supply the table view with the appropriate values for the number of items and the content of each item.

This is a very simplistic example:

- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
    return [array1 count] + [array2 count];

    if(rowIndex >= [array1 count])
        return [array2 objectAtIndex:rowIndex - [array1 count]];
        return [array1 objectAtIndex:rowIndex];

As for selection, well, your controller knows where it's getting its data from, so when the user selects a particular row it should be trivial to translate that row index to a matching object in one of your backing stores.

share|improve this answer

Depending on your application logic, it can make sense. The easiest way would be to set up a different source for every table section. Then, you could use the section number as a selector to your data base.

share|improve this answer

Your Answer


