Notifying the active view of background task completion
I have a tab-based application with a number of navigation controllers in the tabs. Each view can (potentially) have need for data that I manage using a si开发者_Go百科ngleton class.
The singleton class downloads data asynchronously and my problem is: How should I notify the active view (or all views?) that the data has completed.
In the Java world, the views would register themselves as listeners on the singleton, but that does not seem very objective-c-ish.
Please note that I do have solutions to this, none very pretty, and I want to do this the correct way (part of the objective here is to find good patterns for various things).
Basically, I want to broadcast "Hey, I'm done" to either the active view, a view that registers itself as active using "my" api, or all views. Without having to keep track of the views from the singleton.
There is method [NSObject performSelectorOnMainThread:], that's for one view. Or, you can use NSNotificationCenter.
精彩评论