我需要解析一些触发NSURLConnection的XML。解析完成后,我收到一些数据,然后设置根视图控制器。我的问题是application:didFinishLaunchingWithOptions:在composeRootController方法之前返回,并且因为应用程序找不到任何根视图控制器而发生错误。我怎么能等到composeRootController返回?
我的代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self xmlConnect];
return YES;
}
这里实现了xmlConnect函数来解析
- (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];
}
这里composeRootController设置rootcontroller
答案 0 :(得分:0)
点亮你的
[self composeRootController];
内部 didFinishLaunching ...
让composeRootController调用xmlConnect。
您可能必须将xmlConnect方法移出应用代理。