开发者

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 sett开发者_如何学Cing, 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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜