Populating a NSTableView - HELP !!!!

Discussion in 'Mac Programming' started by Fritzables, Jun 10, 2011.

  1. macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #1
    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:
    Code:
    NSMutableDictionary *unitOfMeassure;
    In the 'm' file I have:
    Code:
    self.unitOfMeassure = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    		        @"centimeter/sec^2(cm/s^2)",kUnit,
    			@"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,
    			nil];
    

    I have declared the view like:
    Code:
    IBOutlet NSTableView *inputUnit;
    So in the 'm' file how do I get the Dictionary into the TableView ??

    Pete :mad:
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
  3. thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #3
    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.
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Great. So which of the two methods of providing data to the table view are you using? Binding or the datasource methods?
     
  5. thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #5
    Sorry Robbie,

    I guess it will have to be datasource from what I am reading ?!?!
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    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.
     
  7. thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #7
    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.

    Pete
     
  8. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    Well basically your object implements the methods defined by the protocol. 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:

    Code:
    @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 it shows the sort of method bodies you should be thinking about.
     

Share This Page