0
我需要解析一些觸發NSURLConnection的XML。解析完成後,我收到一些數據,然後設置根視圖控制器。我的問題是應用程序:didFinishLaunchingWithOptions:在composeRootController方法之前返回並且因爲應用程序找不到任何根視圖控制器而發生錯誤。我怎麼才能等到composeRootController返回?didFinishLaunchingWithOptions找不到任何根控制器
我的代碼如下:
- (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
@Jaume - 如果你喜歡這個答案,請投票。謝謝! – Rayfleck