问题
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