开发者

Respond to applicationWillEnterForeground in a UIView

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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜