• 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: userDefaultsDidChange is causing a loop with dependent checkbox values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: userDefaultsDidChange is causing a loop with dependent checkbox values


  • Subject: Re: userDefaultsDidChange is causing a loop with dependent checkbox values
  • From: Reinhard Segeler <email@hidden>
  • Date: Sun, 13 Jun 2010 09:05:53 +0200

How do you bind them to your checkbox?

Do other checkboxes change the NSUserdefaults also, when one setting changes, then this can cause the loop, depending hwo they influence each other!

When binding values with defaults - or other settings - you don't need NSUserDefaultsDidChangeNotification or userDefaultsDidChange(), because the binding updates the values for you. It maybe that the value currently used is not registered in the NSUserdefaults database. But I think, that with bindings this problem should not occur.


-- Reinhard

Am 12.06.2010 um 20:25 schrieb Adam Gerson:

I have set up some NSUserDefaults and used bindings to bind them to
some checkboxes and radiobuttons in my nib. I want the act of checking
some of the checkboxes to uncheck or check other checkboxes. I did
this by registering for a NSUserDefaultsDidChangeNotification.

Then inside userDefaultsDidChange() I have some if statements that
check the current value of checkbox A and set checkbox B to what I
want it to be. However the problem I am having is that

[checkboxB setState:0] only changes the value on the screen but does
not update the defaults saved value in the file and changing the
default directly with [defaults setBool:NO forKey:@"checkboxB"] causes
a loop by calling userDefaultsDidChange() again.
This must cause a loop, if [defaults setBool: ...] is set in the userDefaultsDidChange() method, because you change a defaults value and want to be informed about that, isn't it?



What is the right way to achieve this kind of one checkbox dependent on anothers value with NSUserDefaults and bindings?

I am using settings from defaults and in other ways, bound them in combination with NSValueTransformer, that works nice, for the display on screen, but could be used also to change defaults. But the trick is not the binding alone, it seems, that your combination of settings is the problem: CheckboxA changes CheckboxB changes CheckboxD changes CheckboxA...



Thanks, Adam _______________________________________________

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

_______________________________________________

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: 
 >userDefaultsDidChange is causing a loop with dependent checkbox values (From: Adam Gerson <email@hidden>)

  • Prev by Date: Re: userDefaultsDidChange is causing a loop with dependent checkbox values
  • Next by Date: Re: NSArrayController/Modal dialog/KVO Gordian knot
  • Previous by thread: Re: userDefaultsDidChange is causing a loop with dependent checkbox values
  • Next by thread: Interference of a variable name with Interface Builder
  • Index(es):
    • Date
    • Thread