I'm new to iphone app development and I try to build an app with a splash screen. I need the splash screen, because my app needs to load a xml file from the web. during this, the app should show a splash screen (logo + message "loading xml...") and after successful loading it should proceed to the main screen.
I started the app with a tabbar template, because this should be shown after the splash screen. the first tab has a navigation controller (configured in IB) which loads a custom view controller (I called it searchViewController.h/.m/.xib) on his stack.
my problem: if I run my app, the screen keeps for a long time black and then there is very shortly the splash-screen shown (as it moves down/disappearing) and then the tabbar with the other attached views are shown. but while the screen is black, I can see in the console my control NSLog-messages from the XML parsing.
this means: the app starts, fetching XML, parsing XML, showing splash screen for about 1ms and then show the main app. but I want it to show the splash screen already during the XML fetching and parsing.
my AppDelegate.m:
#import "AppDelegate_iPhone.h"
#import "startPage.h"
@implementation AppDelegate_iPhone
@synthesize window;
@synthesize tabBarController;
@synthesize theVendors;
#pragma mark -#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {
[window addSubview:tabBarController.view];
//initialise the splash screen from class startPage as loadingPage
startPage *loadingPage = [[startPage alloc] init];
//present splash screen as modalview of the tabbar controller
[self.tabBarController presentModalViewController:loadingPage animated:NO];
//make the hole thing visible (should be visible, but isn't (that's the problem))
[self.window makeKeyAndVisible];
//call the splash-screen controller for doing the XML work
[loadingPage initVendors];
[loadingPage release];
return YES;
}
and now the spash-screen method for the XML stuff:
-(void)initVendors{
vendors *theVendorsLocal = [[vendors alloc] initWithDictionary];
NSURL *xmlURL = [NSURL URLWithString:@"http://.../muuhh.xml"];
fParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[fParser setDelegate:theVendorsLocal];
[fParser setShouldProcessNamespaces:NO];
[fParser setShouldReportNamespacePrefixes:NO];
[fParser setShouldResolveExternalEntities:NO];
[fParser parse];
[xmlURL release];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
//AppDelegate_iPad *del = (AppDelegate_iPad *)[UIApplication sharedApplication].delegate;
//del.theVendors = theVendorsLocal;
}else{
AppDelegate_iPhone *del = (AppDelegate_iPhone *)[UIApplication sharedApplication].delegate;
del.theVendors = theVendorsLocal;
}
//detach the modalview from the tabbar controller
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
so the problem is, that the whole parsing stuff is done BEFORE the splash screnn is shown.
why??
as you can see, I load the tabbarcontroller.view, put it as subview of window, set the modalview and do the [self.window makeKeyAndVisible] before I call the [loadingPage initVendors]; method...
why is the splash screen shown after the whole parsing stuff (actually it's not even shown, I just see how it slides out)??
thanks for any help...
I tried to move the [self.window makeKeyAndVisible] to the very top, but the results are still the same:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
breakpoint1 -> [self.window makeKeyAndVisible];
breakpoint2 -> [window addSubview:tabBarController.view];
//initialise the splash screen from class startPage as loadingPage
breakpoint3 -> startPage *loadingPage = [[startPage alloc] init];
//present splash screen as modalview of the tabbar controller
[self.tabBarController presentModalViewController:loadingPage animated:NO];
...
I also tried around with other arrangements, nothing worked. finally I started setting breakpoints and using NSLog to show me, how the app is calling every method. while observing the screen, I found out, that the method-call of [self.window makeKeyAndVisible] doesn't show the view directly after the call..
I marked the breakpoints in the source code above: I would have assumed, that after breakpoint1 the black screen would disappear and a white screen is shown (the window) and afterwards at breakpoint2 the tabbar is shown (at least at breakpoint3). but nothing happens. the screen remains black until the whole idFinishLaunchingWithOptions-method is finished.
I also placed some breakpoints in the applicationDidBecomeActive-method, which is called after the didFinishLaunchingWithOptions-method. if the debugger breaks in one breakpoint in the applicationDidBecomeActive-method, even then there is nothing shown on the screen, the screnn still remains black.
finally after leaving the applicationDidBecomeActive-method the tabbar is shown.
I have no clou, where the app "goes" after leaving the applicationDidBecomeActive-method.
And I would like to know, where and when the tabbar is actually shown?
why does [self.window makeKeyAndVisible] doesn't show the window if I stop at a b reakpoint directly behind this call?