2011-01-19 34 views
0

在該要點是,我在我的UITableView使用JSON數據:https://gist.github.com/786829UITableView的JSON數據分揀部

予取數據標記輸入,並將其格式化以輸出,使得我可以在UITableView的部分acurately顯示它。這是用這個代碼完成的:

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應用程序列表,即自動進行分組。

+0

有時候在謂詞中使用替代變量的速度更快 – Rich 2011-01-19 21:14:44

回答

0

您是否遇到特定問題或僅詢問最佳做法?這對我來說看起來很好,只是不要忘記在將它添加到輸出數組後,纔會發佈你的group字典。

+0

我想知道是否有這樣做,而不是在tableview中顯示這些部分。 – ajayjapan 2011-01-19 21:51:21