3

I have a setting's bundle with some UI customization,

the thing is that if the app is closed and i change a setting, when i open it it is updated. But in iOS 4, if the app is on background and i change a setting, it doesn't updates at all until i close the app and reopen it.

My NSUSerDefaults reading code is something like:

NSUserDefaults *savedData = [NSUserDefaults standardUserDefaults];
NSInteger size = [savedData integerForKey:@"size"];

is on viewWillAppear, since this method should be called everytime the view is loaded, being that it is being started or coming from background.

There's a lot of NSUserDefaults code out there, but all there is missing is [savedData synchronize]; and this seems to be meant to update the defaults once you change them in your app, not the other way around (being changed in the setting, trying to retrieve them)

What am i missing here?

ferostar
  • 7,074
  • 7
  • 38
  • 61

1 Answers1

2

viewWillAppear is not called when the app comes from the background, despite the fact that, well, the view will appear...

So you have to call your update methods from the applicationWillEnterForeground in your app delegate.

See Why does viewWillAppear not get called when an app comes back from the background?

Community
  • 1
  • 1
mvds
  • 45,755
  • 8
  • 102
  • 111
  • Wow, didn't see that coming. Thanks for the answer and for the link, as soon as i got home i'l try it and granted the answer as resolved. – ferostar Mar 28 '11 at 19:58
  • There are typically two ways: Either through IB, by marking your property as `IBOutlet` and wiring it appropriately, or in code after you alloc/init it. It really depends on the situation. But I think this is a different question than the viewWillAppear issue. – mvds Mar 28 '11 at 23:58
  • Sorry for the trouble, i erased the comment asap because i figured out a way to do it, you where WAY too fast answering! Now it works, only that the view is loaded with the previous state and then it changes to the new one. Is this impossible to overcome? – ferostar Mar 29 '11 at 00:10