[英]UITableView JSON Data sorting for sections
這個要點是我在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應用程序列表,該列表會自動進行分組。
您是否有特定問題或只是在詢問最佳做法? 在我看來,這很好,只是在將其添加到輸出數組后不要忘記釋放group
字典。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.