[英]NSURLConnection delegate and populating table view
我必須致電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];
}
如您所見,我嘗試打印出數組中的條目數,當在NSURLConnection的委托中獲得5時,在tableView numberOfRowsInSection中獲得0。 我想使用從NSURLConnection獲得的數據填充表。 我怎樣才能做到這一點?
我看到兩個潛在的問題:
您是否保留結果指向的數組? 我認為您需要調用setResults
(如果已合成)或顯式保留。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.