• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects


  • Subject: Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 8 Dec 2008 09:39:56 -0800

On Dec 8, 2008, at 04:18, Steven Hamilton wrote:

I have a custom NSWindowController called budgetController. Interface thus (cropped a bit)

@interface MLBudgetController : NSWindowController {

	IBOutlet NSArrayController *incomeEnvelopeController;
	NSManagedObject *selectedIncomeEnvelope;
}

My window has an NSPopupButton bound to my NSArraycontroller *incomeEnvelopeController. The selectedObject binding is bound to the selectedIncomeEnvelope above. The controller sources Core Data for my "Envelope" entities and on running, it fetches and displays the set of entities fine showing the correct values. It also sets the selectedIncomeEnvelope fine too.

But on first load I have a "No Value" in the popup. Selecting an entry removes the No Value from the list. In my budgetController's windowDidLoad{} function I'm attempting to set the selectedIncomeEnvelope to the first object in the array like so;

selectedIncomeEnvelope= [[incomeEnvelopeController arrangedObjects] objectAtIndex:0];

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.

Or, if you don't want to define the property explicitly, then you have to generate the notification yourself:

[self willChangeValueForKey: @"selectedIncomeEnvelope"];
selectedIncomeEnvelope= [[incomeEnvelopeController arrangedObjects] objectAtIndex:0];
[self didChangeValueForKey: @"selectedIncomeEnvelope"];



_______________________________________________

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


References: 
 >Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects (From: Steven Hamilton <email@hidden>)

  • Prev by Date: Re: NSDictionary mutability test
  • Next by Date: Re: NSDictionary mutability test
  • Previous by thread: Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
  • Next by thread: Re: NSArrayController, NSPopupMenu, defaults and arrangedObjects
  • Index(es):
    • Date
    • Thread