Binding NSTabViews in NSCollectionViews?

  • I have the following very simple setup (project can be found at http://www.skia.net/media/tabbinding.zip)
    :

    o MyController has but one ivar: NSArray *myNumbers
    o myNumbers is assigned an array of NSNumbers (0,1,2,0,1,2...) in -
    wakeFromNib
    o The app's nib instantiates MyController
    o The app's window is completely filled with an NSCollectionView whose
    content property is bound to MyController.myNumbers
    o NSCollectionView's NSCollectionViewItem's "view" outlet is connected
    to an NSTabView
    o The NSTabView has three tabs. Its SelectedIndex property is bound to
    the representedObject of the NSCollectionViewItem
    o Finally, each tab has a label in it. This label's value property is
    ALSO bound to the representedObject of the NSCollectionViewItem.

    Here's what it looks like when run: http://www.skia.net/media/tabbinding.png

    Note that NSTabView's binding of SelectedIndex works just fine. First
    the 0 index tab is selected, then the 1, then the 2, etc. etc. The
    trouble is the label.

    Each tab should display the index number it is bound to in its label.
    In the picture above, only the first tab (index 0) is actually able to
    find the value it's bound to. The reason? That's the tab selected in
    IB!! If I select the second tab (index 1) in IB, I get the following:
    http://www.skia.net/media/tabbinding2.png

    For some reason, bindings of controls in the initial tab (the one
    selected in IB) work fine, but all the rest are dead. This only
    happens within an NSCollectionView. If drop my NSTabView on the window
    directly, all the bindings in all the tabs work.

    Anybody know what NSCollectionView is doing with its
    NSCollectionViewItem behind the scenes that messes tab views up? I'm
    dumbfounded!

    Many thanks,
    -Joshua Emmons
  • >
    > From: Joshua Emmons
    >
    > For some reason, bindings of controls in the initial tab (the one
    > selected in IB) work fine, but all the rest are dead. This only
    > happens within an NSCollectionView. If drop my NSTabView on the
    > window directly, all the bindings in all the tabs work.

    I've read somewhere on this list that the collection view decodes the
    prototype view and recreates its bindings. But I assume the subviews
    bindings (like in your example) are certainly not recreated.
    If you bind your TextField manualy in – newItemForRepresentedObject:
    it will do the trick.
  • >> For some reason, bindings of controls in the initial tab (the one
    >> selected in IB) work fine, but all the rest are dead. This only
    >> happens within an NSCollectionView. If drop my NSTabView on the
    >> window directly, all the bindings in all the tabs work.
    >
    > I've read somewhere on this list that the collection view decodes
    > the prototype view and recreates its bindings. But I assume the
    > subviews bindings (like in your example) are certainly not recreated.

    Except that the bindings work for the text field in the selected tab
    -- which is a subview just as deep as the other tabs that do not
    display their bindings correctly. Why would it work in the one and not
    the others?

    Also, you can link the CollectionViewItem's "view" outlet to a plain
    old NSView and stack as many NSView subviews as you want on top of it.
    If you drop a text field 16 subviews down and bind its value to
    NSCollectionViewItem.representedObject, it works just fine. So I
    suspect subviews have nothing to do with the problem.

    But if no one else has any ideas, I'll file a radar and move on. It'd
    be nice to get a little more transparency on what exactly
    NSCollectionView is doing with its NSCollectionViewItem, though. It
    would save me a lot of code to use these classes, but every time I try
    to do something even a little bit different than IKImageBrowserView I
    stub my toe on something odd and unexplainable like this.

    Cheers,
    -Joshua Emmons
  • I can see that your simple demo example fails to perform as expected.
    One thing that confused me initially is that "MyController" isn't a
    controller, but just an NSObject that contains the array of NSNumbers.

    You mention the simpler case of dropping a single NSTabView on the
    window directly, which works as expected.  It would be interesting to
    know if you are then binding that NSTabView to a single NSNumber in
    MyController, similar to the way you are binding the first case.  If
    the simpler case works, it would then be interesting to subclass
    NSNumber to increment its value by 10 every time its value is
    accessed, so you can tell if the NSTabView causes the NSTextField to
    update its value each time the tab is clicked and the field becomes
    visible.

    If it does update each time, then it would appear that in the original
    NSCollectionView case the NSTextFields that were not initially visible
    were not bound in a way that would allow them to update their value
    when the NSTabView was changed.

    If it does not update each time, then it would appear that NSTabView
    was programmed to assume its subfields did not need updating when they
    become visible, while NSCollectionView was programmed to assume that
    only the visible fields needed initial values.

    That's just my guess as to what I think is happening.

    On Nov 29, 2007, at 10:08 PM, Joshua Emmons wrote:

    > I have the following very simple setup (project can be found at http://www.skia.net/media/tabbinding.zip)
    > :
    >
    > o MyController has but one ivar: NSArray *myNumbers
    > o myNumbers is assigned an array of NSNumbers (0,1,2,0,1,2...) in -
    > wakeFromNib
    > o The app's nib instantiates MyController
    > o The app's window is completely filled with an NSCollectionView
    > whose content property is bound to MyController.myNumbers
    > o NSCollectionView's NSCollectionViewItem's "view" outlet is
    > connected to an NSTabView
    > o The NSTabView has three tabs. Its SelectedIndex property is bound
    > to the representedObject of the NSCollectionViewItem
    > o Finally, each tab has a label in it. This label's value property
    > is ALSO bound to the representedObject of the NSCollectionViewItem.
    >
    > Here's what it looks like when run: http://www.skia.net/media/tabbinding.png
    >
    > Note that NSTabView's binding of SelectedIndex works just fine.
    > First the 0 index tab is selected, then the 1, then the 2, etc. etc.
    > The trouble is the label.
    >
    > Each tab should display the index number it is bound to in its
    > label. In the picture above, only the first tab (index 0) is
    > actually able to find the value it's bound to. The reason? That's
    > the tab selected in IB!! If I select the second tab (index 1) in IB,
    > I get the following:
    > http://www.skia.net/media/tabbinding2.png
    >
    > For some reason, bindings of controls in the initial tab (the one
    > selected in IB) work fine, but all the rest are dead. This only
    > happens within an NSCollectionView. If drop my NSTabView on the
    > window directly, all the bindings in all the tabs work.
    >
    > Anybody know what NSCollectionView is doing with its
    > NSCollectionViewItem behind the scenes that messes tab views up? I'm
    > dumbfounded!
    >
    > Many thanks,
    > -Joshua Emmons
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