insert a plist in a NSTableView using a NSDictionary

  • Hi

    I am trying to insert a plist on to a NSTableView. So
    I have two columns in tableView, one for Key and the
    other for Value.

    plistDictionary_ = [NSDictionary
    dictionaryWithContentsOfFile:kPlistPath];

    How will I load this NSDictionary onto the
    NSTableView?

    What should be the return value in

    - (id)tableView:(NSTableView *)tableView
            objectValueForTableColumn:(NSTableColumn
    *)tableColumn
                row:(int)row {

    Thank you
    DG

          Chat on a cool, new interface. No download required. Go to http://in.messenger.yahoo.com/webmessengerpromo.php
  • >
    >
    > I am trying to insert a plist on to a NSTableView. So
    > I have two columns in tableView, one for Key and the
    > other for Value.
    >
    > plistDictionary_ = [NSDictionary
    > dictionaryWithContentsOfFile:kPlistPath];
    >
    > How will I load this NSDictionary onto the
    > NSTableView?
    >
    > What should be the return value in
    >
    > - (id)tableView:(NSTableView *)tableView
    > objectValueForTableColumn:(NSTableColumn
    > *)tableColumn
    > row:(int)row {

    You don't need this, just bind the table column with nsarraycontroller and
    your dictionary
    to nsarray controller as an object.
  • I am really confused now.
    I don't know how to bind the dictionary to
    NSArrayController.
    What did you mean?

    DG
    --- NSTask <nstask...> wrote:

    >>
    >>
    >> I am trying to insert a plist on to a NSTableView.
    > So
    >> I have two columns in tableView, one for Key and
    > the
    >> other for Value.
    >>
    >> plistDictionary_ = [NSDictionary
    >> dictionaryWithContentsOfFile:kPlistPath];
    >>
    >> How will I load this NSDictionary onto the
    >> NSTableView?
    >>
    >> What should be the return value in
    >>
    >> - (id)tableView:(NSTableView *)tableView
    >> objectValueForTableColumn:(NSTableColumn
    >> *)tableColumn
    >> row:(int)row {
    >
    >
    >
    > You don't need this, just bind the table column with
    > nsarraycontroller and
    > your dictionary
    > to nsarray controller as an object.
    >

          Bring your gang together - do your thing. Go to http://in.promos.yahoo.com/groups
  • Deepak may be this sample code link can help you.

    http://nsstring.blogspot.com/2007/09/binding-in-objective-c.html

    Try this and tell me, if you need help.

    /S

    >
    > On 9/23/07, deepak gopal <deengg...> wrote:
    >>
    >> I am really confused now.
    >> I don't know how to bind the dictionary to
    >> NSArrayController.
    >> What did you mean?
    >>
    >> DG
    >> --- NSTask <nstask...> wrote:
    >>
    >>>>
    >>>>
    >>>> I am trying to insert a plist on to a NSTableView.
    >>> So
    >>>> I have two columns in tableView, one for Key and
    >>> the
    >>>> other for Value.
    >>>>
    >>>> plistDictionary_ = [NSDictionary
    >>>> dictionaryWithContentsOfFile:kPlistPath];
    >>>>
    >>>> How will I load this NSDictionary onto the
    >>>> NSTableView?
    >>>>
    >>>> What should be the return value in
    >>>>
    >>>> - (id)tableView:(NSTableView *)tableView
    >>>> objectValueForTableColumn:(NSTableColumn
    >>>> *)tableColumn
    >>>> row:(int)row {
    >>>
    >>>
    >>>
    >>> You don't need this, just bind the table column with
    >>> nsarraycontroller and
    >>> your dictionary
    >>> to nsarray controller as an object.
    >>>
    >>
    >>
    >>
    >> Bring your gang together - do your thing. Go to
    >> http://in.promos.yahoo.com/groups
    >>
    >
    >
  • On Sep 23, 2007, at 12:25 PM, NSTask wrote:

    > You don't need this, just bind the table column with
    > nsarraycontroller and
    > your dictionary
    > to nsarray controller as an object.

    Please don't push the use of bindings onto a new Cocoa developer.

    -Shawn
  • On Sep 23, 2007, at 12:17 PM, deepak gopal wrote:

    > Hi
    >
    > I am trying to insert a plist on to a NSTableView. So
    > I have two columns in tableView, one for Key and the
    > other for Value.
    >
    > plistDictionary_ = [NSDictionary
    > dictionaryWithContentsOfFile:kPlistPath];
    >
    > How will I load this NSDictionary onto the
    > NSTableView?
    >
    > What should be the return value in
    >
    > - (id)tableView:(NSTableView *)tableView
    > objectValueForTableColumn:(NSTableColumn
    > *)tableColumn
    > row:(int)row {

    You return the data you want to display in the table. You can return
    NSStrings and they will be displayed. You can return other types of
    objects as well however those may require special NSCell subclasses
    or formatters to be used to display correctly.

    We will need more information to fully outline how to do this.

    -Shawn
  • I need to load the contents of a plist onto the
    NSTableView.
    I thought it would be easy to make a dictionary of the
    contents of plist and load it onto the tableView.
    So I wrote :
    plistDictionary_ = [NSDictionary
    dictionaryWithContentsOfFile:kPlistPath];
    Now the NSTableView delegate methods in the datasource
    want me to return the value I need to load in the
    Table. I need to load the plist key and the value in
    the same row of the tableView. How will I do that? I
    think I can achieve that by giving the correct return
    value for the delegate method:
    - (id)tableView:(NSTableView *)tableView
            objectValueForTableColumn:(NSTableColumn
    *)tableColumn
                row:(int)row {
      return [plistDictionary_ objectForKey:[dictArray_
    objectAtIndex:row]] ;
    }

    So the question is:
    What should be the return value for this method?
    I have a NSDictionary with all the contents of plist
    in the format: Key = "value"

    DG
    --- Shawn Erickson <shawnce...> wrote:

    >
    > On Sep 23, 2007, at 12:17 PM, deepak gopal wrote:
    >
    >> Hi
    >>
    >> I am trying to insert a plist on to a NSTableView.
    > So
    >> I have two columns in tableView, one for Key and
    > the
    >> other for Value.
    >>
    >> plistDictionary_ = [NSDictionary
    >> dictionaryWithContentsOfFile:kPlistPath];
    >>
    >> How will I load this NSDictionary onto the
    >> NSTableView?
    >>
    >> What should be the return value in
    >>
    >> - (id)tableView:(NSTableView *)tableView
    >> objectValueForTableColumn:(NSTableColumn
    >> *)tableColumn
    >> row:(int)row {
    >
    > You return the data you want to display in the
    > table. You can return
    > NSStrings and they will be displayed. You can return
    > other types of
    > objects as well however those may require special
    > NSCell subclasses
    > or formatters to be used to display correctly.
    >
    > We will need more information to fully outline how
    > to do this.
    >
    > -Shawn
    >

          Bring your gang together - do your thing. Go to http://in.promos.yahoo.com/groups
  • Well I had read about bindings but hadn't really used
    it anywhere.
    Thank you for the link, its helpful.

    --- NSTask <nstask...> wrote:

    > Deepak may be this sample code link can help you.
    >
    >
    http://nsstring.blogspot.com/2007/09/binding-in-objective-c.html
    >
    > Try this and tell me, if you need help.
    >
    > /S
    >
    >
    >>
    >> On 9/23/07, deepak gopal <deengg...>
    > wrote:
    >>>
    >>> I am really confused now.
    >>> I don't know how to bind the dictionary to
    >>> NSArrayController.
    >>> What did you mean?
    >>>
    >>> DG
    >>> --- NSTask <nstask...> wrote:
    >>>
    >>>>>
    >>>>>
    >>>>> I am trying to insert a plist on to a
    > NSTableView.
    >>>> So
    >>>>> I have two columns in tableView, one for Key
    > and
    >>>> the
    >>>>> other for Value.
    >>>>>
    >>>>> plistDictionary_ = [NSDictionary
    >>>>> dictionaryWithContentsOfFile:kPlistPath];
    >>>>>
    >>>>> How will I load this NSDictionary onto the
    >>>>> NSTableView?
    >>>>>
    >>>>> What should be the return value in
    >>>>>
    >>>>> - (id)tableView:(NSTableView *)tableView
    >>>>>
    > objectValueForTableColumn:(NSTableColumn
    >>>>> *)tableColumn
    >>>>> row:(int)row {
    >>>>
    >>>>
    >>>>
    >>>> You don't need this, just bind the table
    > column with
    >>>> nsarraycontroller and
    >>>> your dictionary
    >>>> to nsarray controller as an object.
    >>>>

    >>>>
    >>>
    >>>
    >>>
    >>> Bring your gang together - do your thing.
    > Go to
    >>> http://in.promos.yahoo.com/groups
    >>>
    >>
    >>

    >

          Bring your gang together - do your thing. Go to http://in.promos.yahoo.com/groups
  • On Sep 23, 2007, at 12:25 PM, NSTask wrote:

    >> I am trying to insert a plist on to a NSTableView. So
    >> I have two columns in tableView, one for Key and the
    >> other for Value.
    >> [...]
    > You don't need this, just bind the table column with
    > nsarraycontroller and your dictionary to nsarray controller as an
    > object.
    >
    When an obvious beginner is asking a question about how to use a table
    view data source, it's asinine to simply give a general reference to
    bindings in response -- see <http://lists.apple.com/archives/Cocoa-dev/2007/Sep/msg00956.html>.  Using a table view data source is a perfectly good way to start
    with Cocoa, in particular to learn about a number of design patterns
    that will be useful in all aspects of Cocoa development.

    It's even more misleading if bindings are inappropriate for the
    problem at hand.  There is no straightforward way to manage the keys
    and values of a *dictionary* using an array controller.

    > plistDictionary_ = [NSDictionary
    > dictionaryWithContentsOfFile:kPlistPath];
    > How will I load this NSDictionary onto the
    > NSTableView?
    > What should be the return value in
    > - (id)tableView:(NSTableView *)tableView
    > objectValueForTableColumn:(NSTableColumn
    > *)tableColumn
    > row:(int)row {
    >
    The difficulty lies in the fact that you're dealing with an unordered
    dictionary as opposed to an ordered array.
    You need some means to impose order on the dictionary.  Typically
    you'd do this by sorting the keys (first, keys are what you use as the
    entry point into the dictionary; second, within the dictionary they
    are unique -- this may not be the case for the values).

    An inefficient but explicit implementation might look like this...

    mmalc

    - (int)numberOfRowsInTableView:(NSTableView *)aTableView
    {
    return [[plistDictionary allKeys] count];
    }

    - (id)tableView:(NSTableView *)tableView
        objectValueForTableColumn:(NSTableColumn *)tableColumn
    row:(int)row
    {
    NSArray *keysArray = [plistDictionary allKeys];
    NSArray *sortedArray =
           [keysArray
    sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

    id keyAtRow = [sortedArray objectAtIndex:row];

    // this assumes you have given the key column the identifier,
    "keyColumn"
    if ([[tableColumn identifier] isEqualToString:@"keyColumn"])
    {
      return keyAtRow;
    }

    // assume no other columns
    return [plistDictionary objectForKey:keyAtRow];
    }
  • Hi Deepak,

    First debugging I would suggest you to do is to nslog plistDictionary
    contents. It looks like your dictionary
    is empty. Can you paste sample of your file contents.

    /S.

    On 9/25/07, deepak gopal <deengg...> wrote:
    >
    > Hi
    >
    > I am using NSArrayController to load two columns of a table View and the
    > Method I am using is
    >
    > - (void)loadArrayController {
    >
    > NSDictionary *plistDictionary = [NSDictionary
    > dictionaryWithContentsOfFile:kPlistPath];
    >
    > NSMutableDictionary *newDictionary = [NSMutableDictionary dictionary];
    >
    > [newDictionary setValue:[plistDictionary allKeys] forKey:@"Methods"];
    >
    > [newDictionary setValue:[plistDictionary allValues] forKey:@"Address"];
    >
    > [tableViewController_ addObject:newDictionary];
    >
    > }
    >
    > and I am getting only brakets in both the fields.
    > What am I doing wrong? or how else should I do this?
    >
    > Thank you
    > DG
    > PS: Attached is a screenshot of my tableView
    >
    >
    > ----- Original Message ----
    > From: NSTask <nstask...>
    > To: <deepak_gopal_21...>; <cocoa-dev...>
    > Sent: Sunday, 23 September, 2007 1:20:36 PM
    > Subject: Re: insert a plist in a NSTableView using a NSDictionary
    >
    > Deepak may be this sample code link can help you.
    >
    > http://nsstring.blogspot.com/2007/09/binding-in-objective-c.html
    >
    > Try this and tell me, if you need help.
    >
    > /S
    >
    >
    >>
    >> On 9/23/07, deepak gopal <deengg...> wrote:
    >>>
    >>> I am really confused now.
    >>> I don't know how to bind the dictionary to
    >>> NSArrayController.
    >>> What did you mean?
    >>>
    >>> DG
    >>> --- NSTask <nstask...> wrote:
    >>>
    >>>>>
    >>>>>
    >>>>> I am trying to insert a plist on to a NSTableView.
    >>>> So
    >>>>> I have two columns in tableView, one for Key and
    >>>> the
    >>>>> other for Value.
    >>>>>
    >>>>> plistDictionary_ = [NSDictionary
    >>>>> dictionaryWithContentsOfFile:kPlistPath];
    >>>>>
    >>>>> How will I load this NSDictionary onto the
    >>>>> NSTableView?
    >>>>>
    >>>>> What should be the return value in
    >>>>>
    >>>>> - (id)tableView:(NSTableView *)tableView
    >>>>> objectValueForTableColumn:(NSTableColumn
    >>>>> *)tableColumn
    >>>>> row:(int)row {
    >>>>
    >>>>
    >>>>
    >>>> You don't need this, just bind the table column with
    >>>> nsarraycontroller and
    >>>> your dictionary
    >>>> to nsarray controller as an object.
    >>>>
    >>>
    >>>
    >>>
    >>> Bring your gang together - do your thing. Go to
    >>> http://in.promos.yahoo.com/groups
    >>>
    >>
    >>

    >
    >
    > ------------------------------
    > Bring your gang together - do your thing. Start your group.<http://in.rd.yahoo.com/tagline_groups_2/*http://in.promos.yahoo.com/groups>
    >
    >
  • On Sep 26, 2007, at 12:14 AM, NSTask wrote:
    > First debugging I would suggest you to do is to nslog plistDictionary
    > contents. It looks like your dictionary
    > is empty. Can you paste sample of your file contents.
    >
    This continues to be misleading...

    > On 9/25/07, deepak gopal <deengg...> wrote:
    >> I am using NSArrayController to load two columns of a table View
    >> and the
    >> Method I am using is
    >>
    >> - (void)loadArrayController {
    >>
    >> NSDictionary *plistDictionary = [NSDictionary
    >> dictionaryWithContentsOfFile:kPlistPath];
    >>
    >> NSMutableDictionary *newDictionary = [NSMutableDictionary
    >> dictionary];
    >>
    >> [newDictionary setValue:[plistDictionary allKeys]
    >> forKey:@"Methods"];
    >>
    >> [newDictionary setValue:[plistDictionary allValues]
    >> forKey:@"Address"];
    >>
    >> [tableViewController_ addObject:newDictionary];
    >> }
    >>
    >> and I am getting only brakets in both the fields.
    >> What am I doing wrong? or how else should I do this?
    >>
    Per my earlier reply:
    **** Do not use bindings/NSArrayController for this task ****

    (a) It's not suitable technology for a newcomer to Cocoa.
    (b) NSArrayController cannot simply manage a dictionary.

    Please look at the code I posted earlier -- it works...

    mmalc
  • On 9/26/07, mmalc crawford <mmalc_lists...> wrote:
    >
    >
    > On Sep 26, 2007, at 12:14 AM, NSTask wrote:
    >> First debugging I would suggest you to do is to nslog plistDictionary
    >> contents. It looks like your dictionary
    >> is empty. Can you paste sample of your file contents.
    >>
    > This continues to be misleading...

    > On 9/25/07, deepak gopal <deengg...> wrote:
    >>> I am using NSArrayController to load two columns of a table View
    >>> and the
    >>> Method I am using is
    >>>
    >>> - (void)loadArrayController {
    >>>
    >>> NSDictionary *plistDictionary = [NSDictionary
    >>> dictionaryWithContentsOfFile:kPlistPath];
    >>>
    >>> NSMutableDictionary *newDictionary = [NSMutableDictionary
    >>> dictionary];
    >>>
    >>> [newDictionary setValue:[plistDictionary allKeys]
    >>> forKey:@"Methods"];
    >>>
    >>> [newDictionary setValue:[plistDictionary allValues]
    >>> forKey:@"Address"];
    >>>
    >>> [tableViewController_ addObject:newDictionary];
    >>> }
    >>>
    >>> and I am getting only brakets in both the fields.
    >>> What am I doing wrong? or how else should I do this?
    >>>
    > Per my earlier reply:
    > **** Do not use bindings/NSArrayController for this task ****
    >
    > (a) It's not suitable technology for a newcomer to Cocoa.
    > (b) NSArrayController cannot simply manage a dictionary.

    I agree that nsarraycontroller can not manage a dictionary well
    and you should go for the earlier code suggested by mmalc.

    /S

    p.s. prev. reply was just the answer of the question not a suggestion for
    implementation.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today