boscarol
boscarol

Reputation: 1941

How apply Setting changes at restart?

I work on a project on iPhone iOS 4 with Xcode 4.

I have a view with a UIButton. The title of the UIButton is set in viewDidLoad. So when app starts, the Button has a title.

However, my app has a Settings bundle and the button title can be also changed in Settings app. So I clic on the home button, my app quits, I go to the Settings app, and set a new button title.

When I quit Settings and restart my app, the button title is not refreshed, it is the old button title. Everything is as I had left.

Only if I turn off the iPhone, then turn on and relaunch my app (i.e. at full restart) the button has at the new title.

How to make sure that the button title changes when the app is (not full) restarted?

Thank you.

Upvotes: 2

Views: 850

Answers (3)

Johan Kool
Johan Kool

Reputation: 15927

You can register to receive NSUserDefaultsDidChangeNotifications and then act accordingly to update your UI.

Upvotes: 0

glorifiedHacker
glorifiedHacker

Reputation: 6420

I was mistaken in thinking that the viewWillAppear message would be sent to the ViewController when the app became active again after switching back from the Settings app. There is a notification posted when the app becomes active, however, so you should be able to accomplish what you want by registering your ViewController to receive UIApplicationDidBecomeActiveNotification notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshButtonTitle:) name:UIApplicationDidBecomeActiveNotification object:nil];

and then create the appropriate method in your ViewController to be called when the notification is fired:

- (void)refreshButtonTitle:(NSNotification *)notification {
// update the title of your button here
}

Upvotes: 0

Daniel G. Wilson
Daniel G. Wilson

Reputation: 15055

You want to update the settings in applicationDidEnterForeground. That gets called when it resumes.

Edit: Had a typo, it should be

- (void)applicationWillEnterForeground:(UIApplication *)application

see docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

Upvotes: 2

Related Questions