Hi everybody that’s my first post here, so i’ll try to be as clear as possible.
So, in my project, I need to get an xml document from a webService, with SOAP, and then parse it in a NSMutableArray (This is done). Then I would like to display my table’s content in a tableview. Problem is, in my delegate I can’t access anything of my viewController.
I have 3 classes, SOAP_TestViewController, SOAP_TestAppDelegate and XMLParser. I’m sending the array containing the parsed file from XMLParser to the Appdelegate, and then I would like to update an array in my viewController to use it in order to update my tableview.
Here’s a bit of code, may help to understand.
#import "SOAP_TestAppDelegate.h"
#import "SOAP_TestViewController.h"
#import "XMLParser.h"
@implementation SOAP_TestAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
NSLog(@"%@", viewController.donnees); //Here I can get what I want.
[window makeKeyAndVisible];
}
-(void)afficher{
NSLog(@"%@", viewController.donnees); //But there, it returns (null)...
[viewController reload];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
I spent like hours to find a solution. AND, I noticed something. Like the comments say in my code, I can access what I want in the applicationDidFinishLaunching function, but not outside. So am I working on copies or something when i’m out of this function ? And what should I do to access my “donnees” table ?
I’m such a beginner in cocoa coding so please tell me if i’m doing things wrong.
(Please be indulgent with my English 🙂 I’m not bilingual yet ^^’)
EDIT
My afficher function looked like this at the beginning. I call it from XMLParser with the parsed array as parameter. I was sur it would work but…
-(void) afficher:(NSMutableArray *)array
{
NSLog(@"%@", array); //returns the array sent by XMLParser.
[viewController.donnees addObjectsFormArray:array];
NSLog(@"%@", viewController.donnees); //returns null.
}
That’s weird, it’s like donnees wasn’t even allocated and initialized…
Are you sure your viewController is not nil? Ok, that’s unlikely. Then are you sure your donnees array is not nil AND it is NSMutableArray, but not NSArray?
And, btw, you CAN access the properties out of appDelegate from anywhere. I’m not fond of this solution, but just to make a clarification on that. In any class you can do smth like:
Of course, donnees should be a property in this case. Cheers!