Best practice for applicationDidEnterBackground [closed]

不打扰是莪最后的温柔 提交于 2019-12-11 06:16:09

问题


I am in the middle of writing an application that needs to reset certain parts of its state to a default state when the application calls applicationDidEnterBackground. What I would like to know is if it is a better practice to get a pointer to the view that needs to be reset and then reset the properties that need to be reset right there in the app delegate, or should I post an NSNotification that the app is entering the background and have the view controller do it's cleanup within itself. Or maybe there's another method I'm not thinking of.

I appreciate any input.


回答1:


These notifications get posted already. Just subscribe to the event in your controller class(es) and do whatever you need to there.

From the docs:

The application also posts a UIApplicationDidEnterBackgroundNotification notification around the same time it calls this method to give interested objects a chance to respond to the transition.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/data/UIApplicationDidEnterBackgroundNotification



来源:https://stackoverflow.com/questions/6063866/best-practice-for-applicationdidenterbackground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!