Reputation: 1258
I am trying to get JSON data loaded from a NSURLConnection
delegate to send the array of objects back to the tableview that called it.
The delegate object is initialized with callback
to send back to
NSArray *returnArray;
ResultsTableRoot *callback;
JSON handling method
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
[responseData release];
NSError *error;
SBJSON *json = [[[SBJSON alloc] init] autorelease];
returnArray = [json objectWithString:responseString
error:&error];
[responseString release];
//////////////////////////////////////////////
// Send data back to table view
[callback resultsArrayReciever:returnArray];
}
The array can't be accessed from here, the tableview I want to have the information, however the method is called
-(void)resultsArrayReciever:(NSArray *)array {
// Code executed
if(array) {
// Code never executes, array isnt there
}
}
If you have a better way to go about this whole thing, it is more than welcome!!
Upvotes: 0
Views: 312
Reputation: 7966
Try retaining the object:
NSError *error;
SBJSON *json = [[SBJSON new] autorelease];
returnArray = [[json objectWithString:responseString error:&error] retain];
[responseString release];
[callback resultsArrayReciever:returnArray];
[returnArray release];
Upvotes: 0
Reputation: 8069
The returnArray
is probably autoreleased. Try retain/releasing it in your methods.
If it is autoreleased the contents will be released in your run-loop and therefore disappear by the time you want to access it.
Upvotes: 1