tags:

views:

262

answers:

1

I have a UITableView that loads remote data from the network. I have logic in viewWillAppear to handle refreshing the data when needed based on state changes and a TTL for the data set. This works fine within an app "session" but isn't effective when the user exits the app to the background and later restores it directly to this view.

What I'm finding is that when the app is restored to the foreground in iOS4 - viewWillAppear is not invoked in the view- I can totally understand why this is by design. Is there another UIView delegate I should be taking advantage of? I didn't spot anything in the docs.

Since willEnterForeground is available in the app delegate is the best way to handle this firing a notification from the app delegate to the view? Am I missing a more direct an elegant way of catching this in a UIView?

Thanks for any tips.

+1  A: 

You are correct about the delegate calls, though for what you are doing it sounds to me like you will want to suspend and resume your network activity based on the methods applicationDidBecomeActive: and applicationWillResignActive: which are both on the app delegate.

In answer to your question about a more direct way of catching these notifications in your UIView, if you do not have convenient access to the app delegate you could register for notification of UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification via the default notification center. That somewhat detaches you from coupling the app delegate to your view.

jbm
Thank you very much. On the pointer for Active/Inactive that makes perfect sense.It was silly to think of a custom notification from the app delegate to the viewcontroller- thanks for pointing out there are system notifications to listen for that cover this. I'll stop making things too hard now :)
Nick