populating a tableview with data using JSON and AFNetworking NSDictionary

前端 未结 1 1756
鱼传尺愫
鱼传尺愫 2021-01-15 18:05

c & ios n00b here,

I have been working on this problem for 3 days. I am worried that there is a fundamental concept that I am missing. I have researched and and

相关标签:
1条回答
  • 2021-01-15 18:22

    If you're self.beers array is properly populated then I think you are not reloading the tableview.

    Add this line after self.beers=[[NSArray alloc]initWithArray:tempArray];

    dispatch_async(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData]
                });
    

    It will reload the tableview after you receive all the data. If that doesn't work then NSLog(@"%@",self.beers); to make sure that self. beers is populated.

    I didn't realize it is giving you an error before actually populating the tableView. I think the problem is that the name is returning a NSString and not an NSArray. Actually the responseObject contains array of dictionaries so that when you iterate through the array you get a dictionary for each beer. This way you can just access the beer name with objectForKey

    Beer *newBeer=[[Beer alloc]initWithName:[oneDictionary objectForKey@"name"]];
    

    to retrieve the name of the beer.

    Let me know if it works out.

    0 讨论(0)
提交回复
热议问题