cocoa bindings NSTableColumn to @allKeys?

  • I have a model object YKKFlickrUser which aggregates an
    NSMutableDictionary called m_photoLists which contains keys for
    another model object, YKKPhotoList(I have accessors -photoLists and
    -setPhotoLists).

    In my controller class I have an NSPopUpButton bound to an
    NSArrayController m_userController. On startup the m_user array is
    populated and m_userController is bound to "AppController
    alias"(NSObjectController, controller key > selection, model key path
    > users).

    The NSPopUpButton displays the users as expected.

    I then created a table with a single table column. Making sure I
    select the table column in IB, In the 'value' binding I

    bind > Flickr Users,
    controller key > "selection",
    model key path > "<photoLists....>"

    I get a "(" in the table column:

    http://img341.imageshack.us/img341/7998/picture1ie4.png

    m_photoLists is an NSMutableDictionary. Is there any reason I should
    use an array instead?

    Mac OS X 10.5.1, IB 3, Xcode 3

    Michael
  • on 12/30/07 12:00 AM, <taomailings...> purportedly said:

    > I then created a table with a single table column. Making sure I
    > select the table column in IB, In the 'value' binding I
    >
    > bind > Flickr Users,
    > controller key > "selection",
    > model key path > "<photoLists....>"
    >
    > I get a "(" in the table column:
    >
    > http://img341.imageshack.us/img341/7998/picture1ie4.png
    >
    > m_photoLists is an NSMutableDictionary. Is there any reason I should
    > use an array instead?

    You are being told that there are multiple values for a single binding. What
    you are doing is binding every row of a table column to the same multiple
    value (@allKeys). I doubt this is what you want.

    You want to bind the value to an array controller that is bound using the
    above options.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • On Dec 30, 2007, at 9:16 AM, Keary Suska wrote:

    > You want to bind the value to an array controller that is bound
    > using the
    > above options.
    >
    This is probably insufficient, since you then need to know what key to
    use in the table column binding (and @allKeys won't work as a keypath).

    On Dec 29, 2007, at 11:00 PM, Michael Hanna wrote:
    > I have a model object YKKFlickrUser which aggregates an
    > NSMutableDictionary called m_photoLists which contains keys for
    > another model object, YKKPhotoList(I have accessors -photoLists and
    > -setPhotoLists).
    [...]
    > bind > Flickr Users,

    > controller key > "selection",
    > model key path > "<photoLists....>"
    >
    Is each key simply a string (as would seem to be the case from the
    spec)?  And do you intend the keys to be editable?

    If both are true, then using an array controller to manage them won't
    work, since the bindings architecture expects to deal with objects
    that themselves have keys and values and an array controller.  If you
    can get the actual dictionary (from which allKeys is derived) then on
    Leopard you can use the NSDictionaryController (bind its content
    dictionary to [Flickr Users].selection.photoLists.theDictionary).

    If each key is simply a string and you just want to display them, then
    you can use an additional array controller, but you need to "fudge" a
    key for the table column binding.

    You bind the array controller's contentArray to [Flickr
    Users].selection.photoLists.allKeys

    You can then bind the table column to:
    [AllKeysArrayController].arrangedObjects.self
    or
    [AllKeysArrayController].arrangedObjects.description

    mmalc
  • On Dec 30, 2007, at 10:53 AM, mmalc crawford wrote:

    > If both are true, then using an array controller to manage them
    > won't work, since the bindings architecture expects to deal with
    > objects that themselves have keys and values and an array controller.
    >
    Hmm, in case this is too confusing, the "and an array controller" bit
    shouldn't be be there.

    The general point is that you can't use an array controller to manage
    a collection of editable strings.

    mmalc
  • Thanks for the suggestion. I seem to be one step closer, but it's not
    quite there..

    I created a new NSArrayController in IB called Flickr Photo Lists:

    NSArrayController
    bind > Flickr Users
    controller key > selection
    model key path > <photoLists....>

    then I set the class to YKKFlickrPhotoLists.

    NSTableColumn
    bind > Flickr Photo Lists
    controller key > arrangedObjects
    model key path > ???

    do I need to enter a model key path? after all -allKeys returns
    NSStrings doesn't it? I can't leave the field empty and I consistently
    get the runtime error:

    [<NSCFString 0xc2d0> addObserver:<NSTableBinder 0x1502c0>
    forKeyPath:@"properties.username" options:0x0 context:0x0] was sent to
    an object that is not KVC-compliant for the "properties" property.
    [<NSCFString 0xc2d0> valueForUndefinedKey:]: this class is not key
    value coding-compliant for the key properties.

    I just threw properties.username in there cause I had to put something ..

    Michael

    On Dec 30, 2007 9:16 AM, Keary Suska <hierophant...> wrote:
    > on 12/30/07 12:00 AM, <taomailings...> purportedly said:
    >
    >> I then created a table with a single table column. Making sure I
    >> select the table column in IB, In the 'value' binding I
    >>
    >> bind > Flickr Users,
    >> controller key > "selection",
    >> model key path > "<photoLists....>"
    >>
    >> I get a "(" in the table column:
    >>
    >> http://img341.imageshack.us/img341/7998/picture1ie4.png
    >>
    >> m_photoLists is an NSMutableDictionary. Is there any reason I should
    >> use an array instead?
    >
    > You are being told that there are multiple values for a single binding. What
    > you are doing is binding every row of a table column to the same multiple
    > value (@allKeys). I doubt this is what you want.
    >
    > You want to bind the value to an array controller that is bound using the
    > above options.
    >
    > Best,
    >
    > Keary Suska
    > Esoteritech, Inc.
    > "Demystifying technology for your home or business"
    >
  • Sorry, I didn't get your reply until now.

    So, yes I did manage to get this working..

    NSArrayController
    bind > Flickr Users
    controller key > selection
    model key path > <photoLists....>  // *had* to have the @ in there
    for it to 'work'

    --deleted all the bogus keys in the Flickr Photo Lists NSArrayController

    NSTableColumn
    bind > Flickr Photo Lists
    controller key > arrangedObjects
    model key path > <blank>  // can leave this blank because IB couldn't
    autocomplete this field due to lack of keys

    Thanks guys!!

    Michael

    On Dec 30, 2007 6:19 PM, mmalc crawford <mmalc_lists...> wrote:
    >
    > On Dec 30, 2007, at 6:12 PM, Michael Hanna wrote:
    >
    >> do I need to enter a model key path? after all -allKeys returns
    >> NSStrings doesn't it? I can't leave the field empty and I consistently
    >> get the runtime error:
    >
    > Umm, I addressed that in my reply.
    >
    > mmalc
    >
    >
  • Each YKKFlickrPhotoList object has an NSMutableDictionary of photos(I
    have -photos and -setPhotos accessors). Flickr Photo List
    NSArrayController is binding to the @allKeys of the m_photoLists
    dictionary in YKKFlickrUser.

    I want to make another tableview with a column that displays the photo
    attributes of the selected photolist. Do I bind to the Flickr Photo
    List NSArrayController? This is only displaying the photolist key
    names ... how do I get at the values that that key represents? Do I
    have to use an NSDictionaryController to do this?

    Michael

    On Dec 30, 2007 10:53 AM, mmalc crawford <mmalc_lists...> wrote:
    >
    > On Dec 30, 2007, at 9:16 AM, Keary Suska wrote:
    >
    >> You want to bind the value to an array controller that is bound
    >> using the
    >> above options.
    >>
    > This is probably insufficient, since you then need to know what key to
    > use in the table column binding (and @allKeys won't work as a keypath).
    >
    >
    > On Dec 29, 2007, at 11:00 PM, Michael Hanna wrote:
    >> I have a model object YKKFlickrUser which aggregates an
    >> NSMutableDictionary called m_photoLists which contains keys for
    >> another model object, YKKPhotoList(I have accessors -photoLists and
    >> -setPhotoLists).
    > [...]
    >> bind > Flickr Users,
    >
    >> controller key > "selection",
    >> model key path > "<photoLists....>"
    >>
    > Is each key simply a string (as would seem to be the case from the
    > spec)?  And do you intend the keys to be editable?
    >
    > If both are true, then using an array controller to manage them won't
    > work, since the bindings architecture expects to deal with objects
    > that themselves have keys and values and an array controller.  If you
    > can get the actual dictionary (from which allKeys is derived) then on
    > Leopard you can use the NSDictionaryController (bind its content
    > dictionary to [Flickr Users].selection.photoLists.theDictionary).
    >
    >
    > If each key is simply a string and you just want to display them, then
    > you can use an additional array controller, but you need to "fudge" a
    > key for the table column binding.
    >
    > You bind the array controller's contentArray to [Flickr
    > Users].selection.photoLists.allKeys
    >
    > You can then bind the table column to:
    > [AllKeysArrayController].arrangedObjects.self
    > or
    > [AllKeysArrayController].arrangedObjects.description
    >
    >
    > mmalc
    >
    >
  • On Dec 30, 2007, at 10:19 PM, Michael Hanna wrote:

    > model key path > <photoLists....>  // *had* to have the @ in there
    >
    Oh, so photoLists is itself a dictionary?
    My apologies for my misunderstanding.

    mmalc
  • On Dec 30, 2007, at 11:08 PM, Michael Hanna wrote:

    > I want to make another tableview with a column that displays the photo
    > attributes of the selected photolist. Do I bind to the Flickr Photo
    > List NSArrayController? This is only displaying the photolist key
    > names ... how do I get at the values that that key represents? Do I
    > have to use an NSDictionaryController to do this?
    >
    It would certainly be easier if you used a dictionary controller
    (which you would use in place of the Flickr Photo
    List array controller).
    You can look at <http://developer.apple.com/samplecode/DictionaryController/index.html> to see how they're configured.

    If you have to target Tiger, then you can in (likely in your own
    custom class, or a subclass of an array controller) observe the Flickr
    Photo List's selection (e.g. selectedObjects) and as that changes get
    the values for the selected key from the selection in the original
    array controller and set the values as the content for the values
    array controller.
    I hope that makes sense?

    mmalc
  • I think I got it, thanks ..

    I want to retain Tiger compatibility(at least for now) so I changed my
    model slightly. I created a YKKFlickrPhoto class. A YKKFlickrPhotoList
    has an NSArray of these.

    I load in all the photos into the photolist. I send
    [m_photosController setObjectClass[YKKFlickrPhoto class]]; //
    (m_photosController is an NSArrayController)
    [m_photosController setContent:photos];

    but [m_photosController content] returns null
    I am certain photos is not null.
    Also tried:     [m_photosController bind:@"contentArray" toObject:photos
    withKeyPath:@"" options:nil];

    here is my observing method:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
    change:(NSDictionary *)change context:(void *)context
    {
    if (context == SelectedObjectsContext)
    {
      if ([[object selectedObjects] count] > 0)
      {
      if ([[object selectedObjects] objectAtIndex:0] != nil)
      {
        // get the photolists for the current user, find the photolist
    that matches the selection
        NSMutableDictionary *currentPhotoLists = [[self currentUser] photoLists];

        YKKFlickrPhotoList *currentPhotoList = [currentPhotoLists
    objectForKey:[[object selectedObjects] objectAtIndex:0]];
        NSArray *photos = [currentPhotoList photos];
        NSLog(@"photos %@", photos);

        [m_photosController setObjectClass:[YKKFlickrPhoto class]];
        [m_photosController setContent:photos];
        //[m_photosController bind:@"contentArray" toObject:photos
    withKeyPath:@"" options:nil];
        NSLog(@"[m_photosController content] %@", [m_photosController content]);
      }
      }
    }
    else
    {
      [super observeValueForKeyPath:keyPath ofObject:object change:change
    context:context];
    }
    }

    I want to bind the photos to a controller so that I can display their
    contents .. suggestions?

    Michael

    On Dec 31, 2007 1:41 AM, mmalc crawford <mmalc_lists...> wrote:
    >
    > On Dec 30, 2007, at 11:08 PM, Michael Hanna wrote:
    >
    >> I want to make another tableview with a column that displays the photo
    >> attributes of the selected photolist. Do I bind to the Flickr Photo
    >> List NSArrayController? This is only displaying the photolist key
    >> names ... how do I get at the values that that key represents? Do I
    >> have to use an NSDictionaryController to do this?
    >>
    > It would certainly be easier if you used a dictionary controller
    > (which you would use in place of the Flickr Photo
    > List array controller).
    > You can look at <http://developer.apple.com/samplecode/DictionaryController/index.html
    >  > to see how they're configured.
    >
    > If you have to target Tiger, then you can in (likely in your own
    > custom class, or a subclass of an array controller) observe the Flickr
    > Photo List's selection (e.g. selectedObjects) and as that changes get
    > the values for the selected key from the selection in the original
    > array controller and set the values as the content for the values
    > array controller.
    > I hope that makes sense?
    >
    > mmalc
    >
    >
  • On Jan 1, 2008, at 10:19 AM, Michael Hanna wrote:

    > but [m_photosController content] returns null
    > I am certain photos is not null.
    >
    Is m_photosController connected properly (i.e. is it possible it is
    nil)?

    mmalc
previous month december 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
31            
Go to today