【发布时间】: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