Re: Binding multiple NSTableView and NSPopupButton to an NSArrayControler
Re: Binding multiple NSTableView and NSPopupButton to an NSArrayControler
- Subject: Re: Binding multiple NSTableView and NSPopupButton to an NSArrayControler
- From: Lorenzo Thurman <email@hidden>
- Date: Tue, 03 May 2011 12:54:28 -0500
On Mon, May 2, 2011 at 3:15 PM, Quincey Morris
<email@hidden>wrote:
> On May 2, 2011, at 12:47, email@hidden wrote:
>
> > anotherItemController
> > Content Array
> > Bind to: MyAppsClass (added an NSObject from palette and set its class to
> MyAppsClass)
> > Controller Key: myMutableArray
>
> If this is what you were calling a "proxy" earlier, it isn't. It's a
> separate instance of MyAppsClass that's (re-)created when the nib is loaded.
>
> I'm assuming that MyAppsClass represents an app delegate singleton. The
> normal way to create it is to place an instance in the MainMenu nib, and
> connect the Application proxy's delegate outlet to it.
>
> If the nib file you're referring to above is actually the MainMenu nib,
> then that's fine. If not, then you've created a second instance -- you
> shouldn't have added a NSObject from the palette, but should have bound to
> the Application proxy instead, using the "delegate" key to get to the
> existing singleton object.
>
> > If I set a breakpoint after the item has been removed and then in gdb: po
> (NSArray*)[mycontroller arrangedObjects] . The removed item is not in the
> array. If during archiving, I do the same, the removed item is back.
>
> You kind of sidestepped the question here. There are, if I understand
> correctly, 2 different array controllers (one for each NIB), both of which
> are supposed to use the same underlying data model array for their content.
> You're not saving the array controllers (at least I hope not), but you're
> saving the underlying data model. Therefore looking at the array controller
> (or even their arrangedObjects) doesn't tell you anything about what's being
> saved.
>
> What you should be trying to resolve, using the debugger, is the question
> of whether there are 2 underlying data model arrays when there should be
> only one. To do that, you need to be looking at the object address of the
> mutable array(s).
>
>
>
So, I finally figured it out, and yes there were two array instances. I
removed what I referred to as the "Proxy object" representing the class that
actually has the mutable array (MyAppsClass) and just changed the File's
Owner to MyAppsClass. My window controller subclass was initially the
File's Owner for that NIB. The bindings for the NSPopupButton are the same
as before. For the Window holding the NSTableView, these are the bindings:
myArrayController Content Array
Bind To:
Files's Owner
Model Key Path
mutable array
NSTableViewColumn Value
Bind To:
myArrayController
Model Key Path
arrangedObjects
I see the error of my ways now. These latest changes were what I initially
setup when building the interface. When I ran the app, I got an error saying
my window controller subclass was not key value compliant for my mutable
array. That sent me down the rat hole of adding an NSObject and changing its
class to MyAppsClass, to give me a path to the mutable array. This felt a
bit hinky anyway.
What I had overlooked was how I was initializing the window controller
subclass. I was using -(id)initWithWindowNibName, which, of course, sets the
owner to the window controller subclass, thus the key value error. What I
needed to do all along was simply use -(id) initWithWindowNibName: owner:.
Setting owner to MyAppsClass. Now File's Owner->mutable array gives me the
correct Key Path and items removed from the table are removed from the popup
button and everything is written out to disk correctly.
One should always RTFM, even if one thinks he/she understands the FM.
Oh well, lesson learned.
Thanks for making me look a bit harder.
--
"My break-dancing days are over, but there's always the funky chicken"
--The Full Monty
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden