View Full Version : Populating a NSTableView - HELP !!!!

Jun 10, 2011, 05:04 AM
Hi All,

I am tearing my hair out here trying my hardest in populating a NSTableView.
I have taken a look on the net but it has confused me no end and I need help bad. All I want to do is populate only.

I have created a dictionary in the header:
NSMutableDictionary *unitOfMeassure;
In the 'm' file I have:
self.unitOfMeassure = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
@"foot/sec^2 (ft/s^2)",kUnit,
@"free fall (g)",kUnit,
@"meter/sec^2 (m/s^2)", kUnit
@"mile/hour second (mi/(h:s))", kUnit,
@"millimeter/sec^2 (mm/s^2)", kUnit,

I have declared the view like:
IBOutlet NSTableView *inputUnit;

So in the 'm' file how do I get the Dictionary into the TableView ??

Pete :mad:

Jun 10, 2011, 05:10 AM
Have you read (and understood) the Table View Programming Guide (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView/TableView.html)?

Jun 10, 2011, 05:14 AM
Certainly have....

Must point out.... I am into my second week as a Mac user coming from Windows where I spent 15 years using Visual Studio.....

Need help adapting.

Jun 10, 2011, 05:17 AM
Certainly have…

Great. So which of the two methods of providing data to the table view are you using? Binding or the datasource methods?

Jun 10, 2011, 05:19 AM
Sorry Robbie,

I guess it will have to be datasource from what I am reading ?!?!

Jun 10, 2011, 06:04 AM
Sorry Robbie,

I guess it will have to be datasource from what I am reading ?!?!

Possibly. I always found it easier to get those working as I learnt to do this before binding existed :eek:

So you need to implement the datasource protocol in whatever object contains the dictionary and tell the table that this object will be acting as it's datasource.

Jun 10, 2011, 06:09 AM
I fully understand that..... but I am having trouble working out how to do that.
I have spent the last two days searching for examples on this and seen soo many variables.

I think the ol'e grey matter needs a rest up for a while - I'll hit it again tomorrow :-)

When I first got into Coloa (last week) is thought it was so alien but I must admit I am slowly getting used to the new environment and some of the stuff ya can do in XCode....... makes VS look sad !!!

I'll get there Rob.


Jun 10, 2011, 06:18 AM
Well basically your object implements the methods defined by the protocol (http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html). You only have to implement the required ones, in this case two. You declare you are implementing the protocol in the .h file of your object:

@interface MyObject : MyBaseClass < UITableViewDataSource >

MyObject is whatever your object class is. MyBaseClass is whatever class you are inheriting from. The protocols between < and > are the ones you are going to implement (this is a comma separated list).

Then in your .m file you provide implementations for the methods defined in the protocols.

If you look at this page (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView/Tasks/UsingTableDataSource.html%23//apple_ref/doc/uid/20000117-BBCBHIJJ) it shows the sort of method bodies you should be thinking about.