Newbie Question: Mutliple tableViews and dataSources in a window

Discussion in 'Mac Programming' started by klaxamazoo, Dec 20, 2010.

  1. klaxamazoo, Dec 20, 2010
    Last edited: Mar 24, 2012

    klaxamazoo macrumors 6502

    Sep 8, 2006
    I've started to learn Objective-C/Cocoa and I have a concept/procedure question on how it implement multiple tableViews in on GUI.

    I wrote a simple program that opens up a .jdi file (it is a simple text document of an array of layers for lithography processing) and then scales the array according to a scale factor. Now I want to update it to take an array of scale factors and also provide a list of the .jdi files that were selected for scaling.

    I attached a screenshot of the GUI showing the layout with the different tableViews.

    - my AppController class only has one datasource available. So all the tableViews show the same data

    1) What is the best way to handle mutliple tableViews and dataSources?
    2) I think the answer is to have multiple instances of either the AppController class or some other class; but then, how do I link the data between the classes?
    3) Is there are particular developer document that you recommend that covers best practices in this type of situation?

  2. Comrade Yeti macrumors newbie

    Nov 3, 2010
    If you look at the documentation for the NSTableViewDataSource you'll see that the tableview asking for data is passed in for each call.

    Test that tableview, and return different data for each tableview as necessary, like this:

    if(tableview == firstTableview) {
       // firstTableview data processing here
    } else if(tableview == secondTableview) {
       // secondTableview data processing here
    } else if(tableview == thirdTableview) {
       // 3rdtableview data processing here
    } else {
       // unknown tableview, should not happen
    Make sure your app controller has outlets to the 3 tableviews and you've labeled them something that makes sense to you, and you can have them all work and serve up 3 different sets of data.
  3. klaxamazoo thread starter macrumors 6502

    Sep 8, 2006
    Thanks! That makes a lot of sense. I'm going to read the documentation and try it out when I get home tonight.

Share This Page