I have the following Code in my XMLAppDelegate.m file:
- (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];
}
I marked the problem. Is there any possibility to pass the loaded data (loadedData) to applicationDidFinishLaunching:?
Thanks in advance..
Where is your
handleLoadedXMLget called? If you want to pass it toapplicationDidFinishLaunchingcan you just have yourhandleLoadedXMLreturn that array and you can then call that method inapplicationDidFinishLaunching.Edit:
Think of it this way:
You first have this:
Note that here you don’t have
self.productsset up yet. It’s only allocated.After your application finished launching, then you have:
This method gets called somewhere, and then it calls the method below to set your
self.products. Not until now is yourself.productspopulated.So if you want
self.productsto be populated inapplicationDidFinishLaunching, you need to call the method that generates the array inapplicationDidFinishLaunching, saydidFinishParsing, and you can doself.products = [self didFinishParsing];, and then it will be set.