【问题标题】:UITableView JSON Data sorting for sectionsUITableView JSON 数据排序部分
【发布时间】:2011-01-19 20:55:19
【问题描述】:

这个要点是我在 UITableView 中使用的 JSON 数据:https://gist.github.com/786829

我将标记为 INPUT 的数据重新格式化为 OUTPUT,这样我就可以在 UITableView 中准确地显示它。这是通过以下代码完成的:

groups = [parsedData objectForKey:@"venues"];

NSArray * distinctTypes = [groups valueForKeyPath:@"@distinctUnionOfObjects.type"];

output = [NSMutableArray array];

  for (NSString * type in distinctTypes) {
    NSPredicate * filter = [NSPredicate predicateWithFormat:@"type = %@", type];
    NSMutableDictionary *group = [[NSMutableDictionary alloc] init];
    [group setObject:type forKey:@"type"];

    [group setObject:[groups filteredArrayUsingPredicate:filter] forKey:@"venues"];
    [output addObject:group];
}

有没有更好的方法来做到这一点? INPUT 当前用于 sencha 应用列表,它会自动进行分组。

【问题讨论】:

  • 在谓词中使用替换变量有时会更快

标签: iphone json uitableview extjs sections


【解决方案1】:

您是遇到具体问题还是只是询问最佳做法?这对我来说看起来不错,只是不要忘记在将 group 字典添加到输出数组后释放它。

【讨论】:

  • 我想知道是否可以在不这样做的情况下在 tableview 中显示这些部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 2011-03-29
相关资源
最近更新 更多