【发布时间】:2010-02-06 21:15:18
【问题描述】:
我已经尝试了几个小时来解决这个问题。我有一些来自 NSURLConnection 的 JSON。这工作正常,我已将其解析为一个数组。但我似乎无法从 connectionDidFinishLoading 方法中取出数组。我在 UITableViewCell 方法中得到(null)。我假设这是保留问题的范围,但我对 ObjC 很陌生,我不知道该怎么做。任何帮助将不胜感激。
干杯。
-(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;
}
【问题讨论】:
标签: iphone objective-c json uitableview nsurlconnection