如何在TableView中显示字典数据

时间:2012-12-10 10:15:18

标签: objective-c ipad ios4

我正在使用Json来解析数据,目前数据在字典中可用,现在我也想在表格视图中显示该数据。 可以请一些帮忙。

1 个答案:

答案 0 :(得分:2)

NSMutableDictionary* dicts = parseJSON;
...
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return dicts.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"myCell"];    
    if (cell == nil) {
        cell =  [[[ UITableViewCell alloc ] initWithFrame:CGRectZero] autorelease];
    }
    cell.textLabel = [[dicts objectIndex:indexPath.row] objectforkey:@"namefield"];
    return cell;
}