Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
- Subject: Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
- From: Steven Hamilton <email@hidden>
- Date: Tue, 9 Dec 2008 21:17:56 +1000
> <snip>
> However, the arrangedObjects array, while existing, contains zero
> objects. I've checked the Outlet is connected ok. A timing issue of
> some sort?
No. Based on the above, your code isn't KVO compliant.
First of all, it's important to realize that nothing is ever bound to
an instance variable (selectedIncomeEnvelope), but to an object
property (MLBudgetController instance, key "selectedIncomeEnvelope").
The two are not the same thing, although KVO will *pretend* there's a
property when there's only a variable (which appears to be your case,
and which is why it works some of the time).
When you go to set the initial selected object, you need to change the
property, not the variable. This is easiest if you actually define the
property (or write the getter & setter):
@property NSManagedObject *selectedIncomeEnvelope;
...
@synthesize selectedIncomeEnvelope;
...
self.selectedIncomeEnvelope= [[incomeEnvelopeController
arrangedObjects] objectAtIndex:0];
That should cause the proper KVO notification to be sent, and for the
correct object to be selected in the user interface.
Ah, I understand. I've implemented the correct property now but I
still have the problem of arrangedObjects returning an empty array
when called in windowDidLoad. So I can't set my property as I have
nothing to set it with. Any ideas why arrangedObjects would return
zero? It's like the window and controls and initialised before Core
Data can return the fetch.
_______________________________________________
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