简体   繁体   中英

How can I update a view's data when it is re-awakened from the background in iOS4?

I've created an app with external settings in the Settings Bundle. Everything works perfectly. I save the data on every user interaction, and read the data on every view switch (using viewDidAppear trigger).

The issue comes when the user exits the application, then goes to Settings, changes a setting, and then re-launches the application. With iOS4, as far as I can tell, the app never really 'quits', it just goes into the background. Thus when the user "re-launches" the app, it returns to the exact same view they left it in, however, none of the settings changes take effect until the user switches views, triggering viewDidAppear and my corresponding variable loading and screen updating functions.

Put simply, my question is:

is there a function analogous to viewDidAppear that can detect that the app has "re-awakened" from background , and where I can then trigger my data read and screen update functions?


To clarify, here is the code that I am trying to call in ChartViewController.m:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [self loadChartSettings];
    [self.tableView reloadData];    
}

I don't even know where I would start putting this in AppDelegate, because all my processing and display generation code is in the ChartViewController.

When your application is re-launched, your application delegate will receive the -applicationDidBecomeActive: message. Implement that method to read the user defaults. Alternatively, if you'd like to do it in another class, register for the UIApplicationDidBecomeActiveNotification notification.

You are probably looking for this function in your UIAppDelegate:

- (void)applicationDidBecomeActive:(UIApplication *)application;

Also, this might be useful to you:

-(void)applicationWillEnterForeground:(UIApplication*)application;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM