Question

I have a -(void) method in my main UITableView class, which I use to refresh the data. It's somewhat complex, so I'm not going to post it here, but it is also called during viewWillAppear, so every time the tableView appears, the data is refreshed properly, except when it is opened from multitasking.

I know that it is just supposed to provide the exact suspended state, but in my type of app, it needs to be refreshed when you open the app, every time.

I've successfully done this:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [self.window.rootViewController viewWillAppear:YES];
}  

Which refreshes the data perfectly, but creates a number of other problems, like screwing up the popViewController animation in my UINavigationController. I'm guessing that's not the best way to do it in the first place. (Anyone know how to fix that?)

What I want to do is to just perform my refreshTableviewData method whenever I launch the app, including when it's multitasking.

Not sure where to go from here, but I would hugely appreciate any suggestions!

Was it helpful?

Solution

I'll throw some ideas out, which may or may not apply, but since I don't have equivalent code to test these against, you'll have to try them instead of me. :-)

Since viewWillAppear: has to call super viewWillAppear:, I'm thinking there's some special UIViewController magic that happens there, that perhaps shouldn't happen at that point in the app's loading process. You say you have a refreshTableviewData method, so why not invoke that in applicationWillEnterForeground:, or at least try to find the bare minimum you can do to refresh your table without calling viewWillAppear.

Other alternatives: you could also have your view controller register for /UIApplicationWillEnterForegroundNotification. Or if that doesn't work, you could try using applicationDidBecomeActive (and/or the equivalent notification). As a last resort, (and this is a borderline hack) when you load up the app, you could put a "Refreshing data..." message on screen, then use an NSTimer to refresh your table's data, say, 1/4 or 1/2 second later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top