【发布时间】:2014-03-17 23:06:22
【问题描述】:
我有一个 NSMutableArray 或 NSDictionaries,我正在尝试对其进行格式化,以便与具有基于 NSDictionary keys 之一的部分的 UITableView 一起使用。
我的NSDicitonary 有两个值
Name
Key
键是数字 1 - N 的 NSString
我已经设法创建了一个唯一值的NSArray,用于填充每个部分的标题,但是我不知道如何拆分 NSDictionariesinto anNSMutableArray 的 NSDictionaries 的 NSMutableArray ` .. 如果这有意义的话。
更新: 为了给我的问题添加更多细节,我有一个 NSMutableArray 的 NSDictionaries。
{
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 中的对象以在单元格中显示正确值的情况?
任何帮助将不胜感激。
【问题讨论】:
标签: ios objective-c uitableview nsmutablearray nsdictionary