ios - 从 AFNetworking 2.0 使用 JSON 加载 UITableView

标签 ios json uitableview afnetworking

我正在尝试使用远程 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/

相关文章:

ios - 点击 UIButton 不会调用其操作,尽管在视觉上它收到了事件

iphone - 自定义TableViewCell imageView框架

javascript - 在javascript中读取json文件

iphone - UITableView 灵活/动态 heightForRowAtIndexPath

uitableview - 如何在 iOS 7 中更改 UITableView 索引栏的背景颜色?

ios - 为什么我在向 Apple 提交应用程序时遇到这么多麻烦?

ios - Swift 关闭然后打开导致加载两次

ios - Google Web 字体无法在 iOS 版 Chrome 中加载

java - 无法使用 jackson 反序列化器反序列化 java.awt.color

json - 在 Swift 中使用 json 中的相同键解码字典