Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Captain-Fungi

macrumors member
Original poster
Oct 20, 2007
34
0
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
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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 ;)
 

Captain-Fungi

macrumors member
Original poster
Oct 20, 2007
34
0
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?
 

Captain-Fungi

macrumors member
Original poster
Oct 20, 2007
34
0
It appears that the row = [tableView selectedRow]; method is not working, always says that the selected row is 0.
 

Captain-Fungi

macrumors member
Original poster
Oct 20, 2007
34
0
Fixed the above problem. I had not connected the App controller NSTableView outlet to the table in the GUI. Thanks anyway.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.