View Full Version : NSTableView questions

Sep 22, 2008, 04:42 PM
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

Sep 22, 2008, 04:48 PM
Each delegate and data source method passes its table view, so you can just check for that at run time. For example:
- (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 ;)

Sep 24, 2008, 12:52 PM
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?

Sep 24, 2008, 01:04 PM
It appears that the row = [tableView selectedRow]; method is not working, always says that the selected row is 0.

Sep 24, 2008, 01:08 PM
Fixed the above problem. I had not connected the App controller NSTableView outlet to the table in the GUI. Thanks anyway.