views:

40

answers:

1

I'll start with a confession here... I'm a real newbie to Objective-C & iPhone programming (started studying in February & coding in March), I have a project that's very ambitious for that level of experience & a very tight deadline to catch an opportunity to give my app a field trial.

My app is Core Data driven & downloads all of it's data on first run which is a choice made because it will be used on sites where 3G network access may not be reliable. I'd like to present a modal view while this happens, nothing fancy just a bit of text to explain, a progress bar or activity indicator, a graphic to pretty it up & button becoming visible when the job is done. I've tried a couple of approaches & failed dismally so no code for that as all but the XIB has been trashed.

At the moment I'm running this code in applicationDidFinishLaunching ...

[self checkDataAndLoadIfNeeded];
[window addSubview:rootController.view];
[window makeKeyAndVisible];

rootController is a TabBarController with nested NavigationControllers. checkDataAndLoadIfNeeded is a method that checks a default for the data being loaded & if it is not YES presents an alert. The delegate method for dismissing the alert then a custom class, DataLoader, which goes about downloading & importing the data.

What's happening is that the rootController view becomes visible before the alert does & the table on the first tab doesn't load any data until the next run of the app. I'm wondering if that data not loading is because I'm doing that in viewDidLoad & whether I'd do better to have it in viewWillAppear or viewDidAppear. When I tried loading the modal view I've built my rootController view still became visible first & my modal view didn't become visible until the data had finished (or almost finished) downloading (the Done button became visible immediately).

Can anyone offer suggestions as to how I can make this work?

Cheers & TIA, Pedro :)

+1  A: 

Sounds like your rootController is not watching for changes in the data. It should not matter if the element is displayed already or if the data loads first. If the data loads later then the UI element should notice that the data is updated and then refresh itself.

Depending on your app design, you should look at the NSFetchedResultsController class and implement it along with its delegate methods. This class is designed to watch the NSManagedObjectContext for changes and when data is saved out to disk, update its delegate with what has changed.

Marcus S. Zarra
Pedro