iPhone UITableView populateing from connectionDidFinishLoading
        Posted  
        
            by fourfour
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by fourfour
        
        
        
        Published on 2010-02-06T21:15:18Z
        Indexed on 
            2010/04/16
            3:03 UTC
        
        
        Read the original article
        Hit count: 674
        
Hey all.
I have been trying for hours to figure this out. I have some JSON from a NSURLConnection. This is working fine and I have parsed it into an array. But I can't seem to get the array out of the connectionDidFinishLoading method. I an am getting (null) in the UITableViewCell method. I am assuming this is a scope of retain issue, but I am so new to ObjC I am not sure what to do. Any help would be greatly appreciated.
Cheers.
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
SBJSON *json = [[SBJSON alloc] init];
NSDictionary *results = [json objectWithString:responseString];
self.dataArray = [results objectForKey:@"data"];
NSMutableArray *tableArray = [[NSMutableArray alloc] initWithObjects:nil];
for (NSString *element in dataArray) {
    //NSLog(@"%@", [element objectForKey:@"name"]);
    NSString *tmpString = [[NSString alloc] initWithString:[element objectForKey:@"name"]];
    [tableArray addObject:tmpString];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
//cell.textLabel.text = [self.tableView objectAtIndex:indexPath.row];
cell.textLabel.text = [self.tableArray objectAtIndex:indexPath.row];
NSLog(@"%@", tableArray);
return cell;
}
© Stack Overflow or respective owner