Stumped by a custom NSView bindings behavior

  • Folks;

    This is the most complex Cocoa issue I've ever had to ask about!
    I hope I can get the question stated well enough for a cogent
    response...

    I have a custom NSView, MyCoolView, that allows me to create a
    configurable display of an array of images.
    NOTE:  I have MyCoolView working perfectly when I have only a single
    instance of it in my nib.
    The problem is when I put a second instance of MyCoolView into the
    nib they both ALWAYS display the same array of images.
    I use -exposeBinding in +initalize to facilitate interaction with
    MyCoolView.
    + (void)initialize
    {
    ...
        [self exposeBinding:@"imagesArray"];
    ...
    }
    MyCoolView also has the appropriate -imagesArray and -setImagesArray.
    [NOTE: setImagesArray is never called directly by me!]

    Over in my AppDelegate I have 2 outlets (coolView1 and coolView2)
    which are connected to the 2 instances of MyCoolView which are in the
    nib.
    At various time I want to be able to display different arrays of
    images in each of these.
    - (void)awakeFromNib
    {
    ...
        [coolView1 bind:@"imagesArray" toObject:self
    withKeyPath:@"imgArray1" options:nil];
        [coolView2 bind:@"imagesArray" toObject:self
    withKeyPath:@"imgArray2" options:nil];
    ...
    }
    The AppDelegate also has the requisite setters and getters for
    imgArray1 and imgArray2 and I always use them.
    And therein is the issue!!!

    When I perform a [[NSApp delegate] setImgArray1:xyz] this spawns the
    expected call to the correct instance of MyCoolView -setImagesArray:
    and all is well with coolView1.

    BUT if I immediately do NSLog(@"CoolView2's imageArray = %@",
    [coolView2 imagesArray]) it has the values xyz!
    And sure enough if I display coolView2 it displays the images in xyz.
    I never see a call made to coolView2's instance of MyCoolView -
    setImagesArray!

    Conversely if I perform [[NSApp delegate setImgArray2:abc] the
    expected call to [CoolView setImagesArray:] is made but now
    [coolView1 imagesArray] is abc.

    I've spent the better part of 2 days trying to pin this down and I'm
    just stumped.
    I'm to the point where my brain wants me to just dupe the class and
    create a MyCoolView2 class but my gut won't let me...
    Anyone have any ideas or seen this before?

    Thank-you for reading this far and ANY thoughts you might share!
    Steve
previous month august 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