我正在尝试使用远程 JSON 文件填充 UITableView。我能够在 repsonseObject 中获取 JSON,但在使用 TableView 时遇到了问题。我将 JSON 存储在一个数组中。
我的请求是这样的:
- (void)makeJSONRequest
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://www.tylacock.com/cheats.json" parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.jsonFromAFNetworking = [responseObject objectForKey:@"ps3"];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
我的 cellForRowAtIndexPath 方法如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *tempDict = [self.jsonFromAFNetworking objectAtIndex:indexPath.row];
cell.textLabel.text = [tempDict objectForKey:@"name"];
return cell;
}
我已检查以确保数据源已连接到 ViewController。我实际上能够使用 AFNetworking 1.X 完成此操作,但由于升级和方法更改,我不知所措。
最佳答案
您正在异步加载数据,因此您必须在设置 jsonFromAFNetworking
后调用 [self.tableView reloadData]
。
关于ios - 从 AFNetworking 2.0 使用 JSON 加载 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19194952/