NSTableView questions

Discussion in 'Mac Programming' started by Captain-Fungi, Sep 22, 2008.

  1. macrumors member

    Joined:
    Oct 20, 2007
    #1
    I am a fairly recent entrant into the world of Xcode and Cocoa programming. I have a quick question regarding NSTableView.

    If i have two tableview objects in my NIB file what is the best way to get them to use separate delegates and data source? I was thinking along the lines of creating a new controller object for each tableview object.

    What is the best way to achieve this?

    Many thanks
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Each delegate and data source method passes its table view, so you can just check for that at run time. For example:
    Code:
    - (int)numberOfRowsInTableView:(NSTableView *)aTableView
    {
        if (aTableView == table1)
            return [array1 count];
        else if (aTableView == table2)
            return [array2 count];
        return 0;
    }
    With methods that use pass a notification, you can call [notification object] to get the table view.

    Or you could just learn bindings and not have to deal with this ;)
     
  3. thread starter macrumors member

    Joined:
    Oct 20, 2007
    #3
    Thanks for the information.

    I am using the Hillegass book and am stuck on chapter 6 page 106.

    I have the tableView setup correctly and I can see that the delegate outlet is correctly functioning when i change selection. The only problem is that my selection does not change the selected row is always at 0.

    Also I have noticed that the actual NSTableView object does not disable/enable when I click the start/stop buttons.

    Can anyone offer any advice?
     
  4. thread starter macrumors member

    Joined:
    Oct 20, 2007
    #4
    It appears that the row = [tableView selectedRow]; method is not working, always says that the selected row is 0.
     
  5. thread starter macrumors member

    Joined:
    Oct 20, 2007
    #5
    Fixed the above problem. I had not connected the App controller NSTableView outlet to the table in the GUI. Thanks anyway.
     

Share This Page