I need to parse some XML that triggers an NSURLConnection. After the parsing finished, I receive some data and then I set the root view controller. My problem is that application:didFinishLaunchingWithOptions: returns before the composeRootController method and an error occurs because the application cannot find any root view controller. How can I wait until composeRootController returns?
My code is the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self xmlConnect];
return YES;
}
here xmlConnect function is implemented for parsing
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//convertim la data a string
NSString *receivedDataAsString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(@"connectionDidFinishLoading %@", receivedDataAsString);
//xml parsing
xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
[xmlParser setDelegate:self];
self.receivedData = nil;
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
[self composeRootController];
}
here composeRootController sets rootcontroller
Put your
inside
didFinishLaunching…
And have composeRootController call xmlConnect.
You might have to move the xmlConnect method out of your app delegate.