我有一个 NSMutableArray
的 NSDictionaries
,我正在尝试格式化以使用 UITableView
,其中有一些基于 NSDictionary keys
之一的部分 .
我的 NSDicitonary
有两个值
Name
Key
键是数字1 - N的 NSString
我已经设法创建了一个 NSArray
的唯一值来填充每个部分的 Headers ,但是我不知道如何拆分这个NSDictionaries的NSArrays如果有意义的话 .
UPDATE: 为我的问题添加更多细节,我有一个NSDictionaries的NSMutableArray .
{
Name: Jack
Key: 1
}
{
Name: John
Key: 1
}
{
Name: Jack
Key: 1
}
{
Name: Jack
Key: 2
}
{
Name: Jack
Key: 3
}
{
Name: Sean
Key: 3
}
{
Name: Sally
Key: 3
}
我想在像这样的UITableView中显示它
Section 1
- Jack
- John
- Jack
Section 2
- Jack
Section 3
- Jack
- Sean
- Sally
我发现我需要做的事情是
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我设法为部分创建了一个uniqueArray
uniqueKeys = [xmlMutableArray valueForKeyPath:@"@distinctUnionOfObjects.Key"];
uniqueKeys = [uniqueKeys sortedArrayUsingComparator:^(id obj1, id obj2) {
return [(NSString *)obj1 compare:(NSString *)obj2 options:NSNumericSearch];
}];
现在我留下了如何在每个部分中找到行数然后将NSDictionary传递给cellforrow中的对象以向单元格显示正确值的情况?
任何帮助,将不胜感激 .
1 回答
希望对你有帮助:
其原始数据:
排序后的输出: