firewall
firewall

Reputation: 638

Show a loading screen at launch in App Delegate

I'm building an app where it needs to load information from an XML file at startup.

I'm calling the fetching method in didFinishLaunchingWithOptions method of the AppDelegate class:

- (BOOL)application:(UIApplication *)application 
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   [self fetch];    
   return true;
}

But I would like to show an image when the app lunches and I want it to disappear when the fetch method finishes.

Any help is greatly appreciated!

Upvotes: 2

Views: 3539

Answers (3)

Malloc
Malloc

Reputation: 16296

I would suggest creating a view controller, so called LoadingViewController as the root controller to be loaded after the appdelegate, make it conform to NSXMLParserDelegate protocol delegate or whatever other XML parser you are using. In the method which get called when parsing is starting, set the loading image, then dismiss it on the method which get called when the parsing is finished.

For instance, NSXMLParserDelegate protocol has the following two methods:

- (void)parserDidStartDocument:(NSXMLParser *)parser{
//Show loading image
}

and

- (void)parserDidEndDocument:(NSXMLParser *)parser{
//Parsing document has finished, dismiss loading image
} 

PS: I don't know which protocol or third party library you are using to parse XML on your project, but I assume they all have handlers for start/end parsing which you should rely on to respectively show/dismiss loading image.

Upvotes: 0

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40018

Here is a blog which does the same. It loads an image on window performs the action and then removes it.

You can also create a SplashViewContrller make it first view controller with you image, load you xaml and when loading is done present you new controller with animation NO

Upvotes: 1

Mitchell Currie
Mitchell Currie

Reputation: 2809

You can very easily use a storyboard to have an initial view controller for loading with an indicator view, and then trigger the next view controller with a segue once loading is done.

Upvotes: 0

Related Questions