2011-01-29 52 views
0

我必須做出NSURLConnection的通話,並具有以下委託:NSURLConnection的代表和填充表視圖

- (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]; 
    } 

正如你可以看到我試圖打印出數組中的條目數,我得到了5當NSURLConnection的委託內部和0時,tableView numberOfRowsInSection。 我想使用我從NSURLConnection獲得的數據填充表格。我怎樣才能做到這一點?

回答

3

我看到兩個潛在的問題:

  1. 你缺少一個保留。行「結果= [NSArray數組]」;是毫無意義的,你應該保留JSONValue爲「results = [[responseString JSONValue] retain];」 (記得在某些時候發佈!)
  2. 另外,你是否在獲取數據後重新載入tableView?你應該做一些像[table reloadData];或[self.tableView reloadData];取決於你的班級結構。
1

你是否保留了結果指向的數組?我認爲你需要撥打setResults(如果它是合成的)或明確保留。