【发布时间】:2014-03-18 22:08:48
【问题描述】:
我有一个 NSMutableArray 的 NSDictionaries,登录时看起来像这样
<__NSArrayM 0x165bcfc0>(
{
SeqN = 122;
Code = 024;
Number = 1;
},
{
SeqN = 132;
Code = 030;
Number = 1;
},
{
SeqN = 124;
Code = 002;
Number = 2;
},
{
SeqN = 114;
Code = 035;
Number = 3;
},
{
SeqN = 144;
Code = 009;
Number = 3;
},
{
SeqN = 444;
Code = 022;
Number = 3;
}
)
我想知道使用数字作为部分创建 UITableView 的最佳方法,所以 UITableView 看起来像这样
Number 1
SeqN 122, Code 024
SeqN 132, Code 030
Number 2
SeqN 124, Code 002
Number 3
SeqN 114, Code 035
SeqN 144, Code 009
SeqN 444, Code 022
我只是迷路了,我不确定是否需要将 NSDictionaries 的 NSMutableArray 溢出到数组数组中?或者有没有更简单的解决方案可以使用我不知道的东西来实现?
我已经设法创建了一个唯一的 Number 数组,用于我的 sectionCount 返回。我不知道如何返回每个部分的行数或拆分数组以便显示正确的数据。
更新
这就是我如何从我的 NSMutableArray 的 NSDictionaries 创建一个 NSArrays 的 NSDictionary
NSMutableDictionary *sortedDictionaryArraysForTableView = [NSMutableDictionary dictionary];
for (NSDictionary *dict in xmlMArray) {
NSString *currNumber = [dict objectForKey:@"Number"];
if(![[sortedDictionaryArraysForTableView allKeys] containsObject:currNumber])
sortedDictionaryArraysForTableView[currNumber] = [NSMutableArray array];
[sortedDictionaryArraysForTableView[currNumber] addObject:dict];
}
【问题讨论】:
标签: ios iphone objective-c nsmutablearray nsdictionary