我有下面的代碼在我XMLAppDelegate.m文件:iOS:如何將數據傳遞給applicationDidFinishLaunching:?
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self.window makeKeyAndVisible];
self.products = [NSMutableArray array];
XMLViewController *viewController = [[XMLViewController alloc] init];
viewController.entries = self.products; // 2. Here my Array is EMPTY. Why?
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:productData]];
self.XMLConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
NSAssert(self.XMLConnection != nil, @"Failure to create URL connection.");
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)handleLoadedXML:(NSArray *)loadedData {
[self.products addObjectsFromArray:loadedData]; // 1. here I get my Data (works fine)
XMLViewController *viewController = [[XMLViewController alloc] init];
[viewController.tableView reloadData];
}
標誌着我的問題。有沒有可能將加載的數據(loadedData)傳遞給applicationDidFinishLaunching:?
在此先感謝..
In respone to number 2.你的數組是空的,因爲你沒有填充任何東西。 – 2012-08-09 22:51:23
爲了響應數字1,你在哪裏調用handleLoadedXML? – 2012-08-09 22:52:04
請注意,您不應該在您的應用代理中進行任何同步網絡呼叫。這可能會降低您的啓動速度,因爲您的應用程序被操作系統退出的風險更大,因爲啓動時間太長。將其更改爲異步請求,或在應用完成啓動後執行請求。 – runmad 2012-08-09 22:56:11