NSTableView, IB & NSUserDefaults

  • I have struggled some days now - searching the archives, playing with
    examples and googling - to figure out how to get an NSTableView to
    place nicely with a full dictionary entry in the user defaults.

    I can get an NSTableView to load an entire dictionary from the user
    bundle and display it properly by using the informal protocol methods:

    - (id)tableView:(NSTableView *)aTableView
        objectValueForTableColumn:(NSTableColumn *)aTableColumn
      row:(int)rowIndex;
    - (int)numberOfRowsInTableView:(NSTableView *)aTableView;

    But what I really want is to be able to have a relatively small
    number of rows (maybe 10 max) to be completely editable, without
    adding much if any code, by leveraging user defaults binding.

    I am fairly sure my difficulty lies in the way I am setting up the IB
    entries for my NSTableView. For example, if I have the following
    dictionary as my example:

    <plist version="1.0">
    <dict>
    <key>records</key>
    <array>
    <dict>
      <key>number</key>
      <integer>97</integer>
      <key>place</key>
      <string>Superior Road</string>
    </dict>
    <dict>
      <key>number</key>
      <string>123</string>
      <key>place</key>
      <string>Main Street</string>
    </dict>
    </array>
    </dict>
    </plist>

    Then when I have the two column bindings for number & place setup as
    'values.number [Shared User Defaults]' and 'values.place [Shared User
    Defaults]' ... I can get the values to show up as root values in the
    defaults plist. And the plist ends up looking like this:

    <plist version="1.0">
    <dict>
    <key>number</key>
    <integer>97</integer>
    <key>place</key>
    <string>Superior Road</string>
    </dict>
    </plist>

    And every row will look the same. However, I am led to logically
    believe that if I also setup the table content bindings entry as
    'values.records [Shared User Defaults]', the table view will
    magically know how to construct the right intersection of data rows/
    columns and maintain an entire row/column dictionary for me.

    Can anyone shed some light on this darkness for me? What little
    tidbit am I missing? Is there some magic to naming of binding entries
    so the right intersection of row&columns occurs?

    Thanks in advance.

    Chris
  • HI:

    I was finally able to get NSUserDefaults binding to (MOSTLY) work
    with an NSTableView without resorting to any code at all. It is
    really neat how the bindings work for an NSTableView are setup. I
    just had to make sure that the NSTableView dataSource was pointing at
    shared defaults, table references were specified, etc. And I don't
    even need to have the delegate of the NSTableView pointing at my
    application controller.

    HOWEVER, what is missing is the ability for in situ table edits to
    stick. I can change a field in the NSTableView, but the moment I
    press enter, tab to the next field or click on another row, the edit
    reverts immediately back to what it had been before the edit. This is
    puzzling as I would expect that the behavior would mimic the behavior
    of all the other user defaults bindings that I have in my application
    which all work as expected, including automatic updates. I receive no
    errors or warnings from the console, leading me to believe I am not
    far off the mark...

    What simple little thing am I am missing?

    Cannot see the forest through the trees...

    TIA, Chris

    On Nov 19, 2007, at 6:15 PM, Chris Heimark wrote:

    > snip...
    > Can anyone shed some light on this darkness for me? What little
    > tidbit am I missing? Is there some magic to naming of binding
    > entries so the right intersection of row&columns occurs?
    >
    > Thanks in advance.
    >
    > Chris
  • On Nov 27, 2007 1:44 AM, Chris Heimark <cjheimark...> wrote:
    > HI:
    >
    > I was finally able to get NSUserDefaults binding to (MOSTLY) work
    > with an NSTableView without resorting to any code at all. It is
    > really neat how the bindings work for an NSTableView are setup. I
    > just had to make sure that the NSTableView dataSource was pointing at
    > shared defaults, table references were specified, etc. And I don't
    > even need to have the delegate of the NSTableView pointing at my
    > application controller.

    If you're using NSTableView bindings, you shouldn't need to use the
    dataSource outlet, which is probably the source (pardon the pun) of
    your problem here. Try going back to just the bindings, and bind each
    NSTableColumn to the correct object/controller with the relevant key
    as the binding model path.

    Dave.
previous month november 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