После изменения настроек по умолчанию я хотел бы обновить данные myViewController, когда я выхожу на передний план в AppDelegate. Я делаю
AppDelegate .m
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview:[navigationController view]];
NSLog(@"APPLICATION DID FINISH LAUNCHING");
// listen for changes to our preferences when the Settings app does so,
// when we are resumed from the backround, this will give us a chance to update our UI
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(defaultsChanged:)
name:NSUserDefaultsDidChangeNotification
object:nil];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
*/
NSLog(@"APPLICATION WILL ENTER BACKGROUND");
[myViewController viewDidLoad];
}
myViewController.m
- (void)viewDidLoad
{
NSLog(@"VIEW DID LOAD IN MY VIEW CONTROLLER");
// watch when the app has finished launching so we can update our preference settings and apply them to the UI
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSettings:)
name:UIApplicationDidFinishLaunchingNotification object:nil];
}
- (void)updateSettings:(NSNotification *)notif
{
myLabel.text = @"data has just been modified";
}
Однако здесь вообще ничего не изменилось.