iPhone Objective C data model class methods that takes time to complete
I have an iPhone app with several view controllers, each of them pulls RSS, images, etc from the web. Right now I have all of the async network calls in the view controllers. I would like to separate this code into a data model class that I can just include so I can get rid of redundant code and make my application easier to maintain/modify.
It would be ideal if I could do the async calls in my model class, then have my view controller call a met开发者_如何学JAVAhod of the model that will return a dictionary/etc. I just don't think I have a proper grasp on the right way to do this. Would I need to use NSNotification? Delegates?
If anyone could point me in the right direction that would be great! Thanks for reading.
When you model is done fetching - i.e. the data is available, have the model post an NSNotification with a unique name for the type of data. Have your view controllers add themselves as observers of that notification. This decouples the 2 layers nicely.
精彩评论