Possible Duplicate:
How can I save and load the alpha values of a UIButton in an app?
I would like to save the state of the UIButton (e.g. its alpha value and whether it is hidden or not) and this would then load up when the user quits and reloads the app.
I've tried some bits of code with NSUserDefaults but with no luck.
Could somebody help with some sample code so that I can save and load the button's state?
Thanks,
James
Related to Shaharyar's answer (i don't know how to comment):
in this case you need to use NSNumber.
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithFloat:SOME_FLOAT] forKey:KEY];
because
float
is not an object, butNSNumber
is one.EDITED:
1) To make sure your defaults are created after the application runs at first time: in your AppDelegate's
initialize
-method:2) Updating defaults after:
3) Read defaults:
Can you post some of the code?
NSUserDefaults
is the place to store such information..Assumption:
Did you make a call to
[NSUserDefaults synchronize]
after setting the values?Code:
In your case it would be: