I have to make a call to NSURLConnection and have the following delegate:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
[responseData release];
results = [NSArray array];
results = [responseString JSONValue];
NSLog(@"Number of rows: %d", [results count]);
}
//table view number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
//return [_userInfo.friendsInfo count];
NSLog(@"Number of rows: %d", [results count]);
return [results count];
}
As you can see I tried to print out the number of entries in the array and I got 5 when inside the delegate for NSURLConnection and 0 inside the tableView numberOfRowsInSection. I would like t开发者_开发技巧o use the data that I got from the NSURLConnection to populate the table. How can I do this?
I see two potential problems:
- You are missing a retain. The line "results = [NSArray array];" is pointless, and you should retain the the JSONValue as "results = [[responseString JSONValue] retain];" (remember to release at some point!)
- Also, are you reloading the tableView after you get the data? You should do something like [table reloadData]; or [self.tableView reloadData]; depending on your class structure.
Are you retaining the array that results points to? I think you need to call setResults
(if it is synthesized) or explicitly retain.
精彩评论