• 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
Bindings/NSUserDefaultsController issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings/NSUserDefaultsController issue


  • Subject: Bindings/NSUserDefaultsController issue
  • From: Loukas Kalenderidis <email@hidden>
  • Date: Tue, 27 Feb 2007 13:04:03 +1100

Hi Guys,

I'm having a bit of a problem with values persisting when they are manually set using setValue:forKey: via an NSUserDefaultsController. I'm probably doing (or missing) something silly, but it's been a while since I've worked with bindings.

I have an NSArrayController object whose contentArray aspect is bound to an NSUserDefaultsController instance with the controller key "values" and the model key "nestingGaps" as such:

http://pad.au.com/~ms/binding.png

Note "Handles Content As Compound Value" is set, otherwise data does not seem to persist at all.

A pretty standard NSTableView setup with buttons bound to add and remove:

http://pad.au.com/~ms/tableview.png

Everything so far seems to work fine. The problem I'm having is with the "Make Default" button which is connected to the following action:

- (IBAction)makeNestingDefault:(id)sender {
	NSArrayController *controller;
	NSEnumerator *e;
	id obj;

if([sender tag] == 0)
controller = nestingGapsController;
else
controller = nestingMarginsController;

// Clear default flag
e = [[controller arrangedObjects] objectEnumerator];
while(obj = [e nextObject])
[obj setValue:[NSNumber numberWithInt:0] forKey:@"default"];

// Set selected object as default
[[[controller selectedObjects] objectAtIndex:0] setValue:[NSNumber numberWithInt:1] forKey:@"default"];
}


nestingGapsController is the NSArrayController in question (there are actually two sets of table view/buttons/etc - one for gaps and one for margins, but that's irrelevant here).

The idea of this is fairly obvious - to clear the default flag on all rows, and set the default flag on the selected row. This _appears_ to work (it's reflected in the interface, and using something like `po [[controller selectedObjects] objectAtIndex:0]` in the debugger after the last line of the makeNestingDefault function reflects the change:

(gdb) po [[controller selectedObjects] objectAtIndex:0]
<NSCFDictionary 0x6067f0>{
gap = 6;
default = 1;
}

Now, even after calling the NSUserDefaultsController's save: method (it's set to apply immediately, so this shouldn't matter), the actual defaults system doesn't reflect the change:

(gdb) call (void)[userDefaultsController save:nil]
(gdb) po [[userDefaultsController defaults] objectForKey:@"nestingGaps"]
<NSCFArray 0x317e00>(
...snip...
<NSCFDictionary 0x3ccbc0>{
gap = 6;
}
...snip...
)

But the NSUserDefaultsController does:
(gdb) po [[controller selectedObjects] objectAtIndex:0]
<NSCFDictionary 0x6067f0>{
gap = 6;
default = 1;
}

Can anyone explain what's happening here? Is there some other way I'm supposed to set values programmatically in the user defaults in this scenario (ie. via NSUserDefaults directly rather than through the NSUserDefaultsController)?

Thanks,
Loukas
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Bindings/NSUserDefaultsController issue
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Help: Mac as a Terminal
  • Next by Date: launchctl - no response
  • Previous by thread: Re: NSTask with admin power
  • Next by thread: Re: Bindings/NSUserDefaultsController issue
  • Index(es):
    • Date
    • Thread