【问题标题】:how to display dictionary data in TableView如何在 TableView 中显示字典数据
【发布时间】:2012-12-10 10:15:17
【问题描述】:

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

【问题讨论】:

  • 您只需要从字典的键中获取值并将其传递到 tableview 的 cellForRowAtindexPath 数据源中..
  • 您是否使用对象将数据保存在 nsmutablearray 中?

标签: objective-c ipad ios4


【解决方案1】:
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;
}

【讨论】:

    猜你喜欢
    • 2020-03-28
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2021-07-13
    • 2021-11-05
    • 1970-01-01
    相关资源
    最近更新 更多