views:

30

answers:

1

I have a tab-bar and navigation controller application (like Youtube app or Contacts app).

Where is the correct place to have the code for loading some data from the web? These data are necessary for all the tabs of the Tab Controller and the app can't display anything before all data are downloaded and parsed from the app (except a loading indicator view of course).

Up to now I put it in the AppDelegate but it somehow doesn't feel right..

What's the correct way to do it?

Thanks!

A: 

For a simple application, doing this in the application delegate is okay. I would probably do it in my main view controller, however. I would also probably put some defaults on those tabs so that the user sees something there, even if there is no internet connection (although this may vary between apps, and may not be appropriate in your case).

The most important thing to remember is that wherever you start loading this data (whether it's in the app delegate or your controller's viewDidLoad method), you should kick-off whatever downloads you need and establish whatever notification system is appropriate and return as quickly as possible. I.e., don't block in either of these delegate methods.

In general, though, since it sounds like this data is related to the display you are creating, it's probably appropriate to contain it's loading inside the view controller itself.

Jason Coco
That's my issue; I don't have a main view controller... The AppDelegate creates the UITabBarController, and one UINavigationController for each tab, initialised with each one's RootViewController, and finally I add the UITabBarController's view as a subview to the window. There is not a main view controller, but one view controller for each tab. Am I doing it wrong?
cgp
@cgp: In that case, your application delegate is kind of acting as your main view controller, so I think it is entirely appropriate that you load the data there.
Jason Coco