【发布时间】:2013-09-15 15:00:40
【问题描述】:
我有一个名为 records 的 NSMutableArray,其中包含一些单条记录。所以结构是这样的:
- 记录
- 记录(“名称”:“test1”,“时间戳”:“2013-09-15 12:34:35 +0000”)
- 记录(“名称”:“test2”,“时间戳”:“2013-09-14 11:21:42 +0000”)
- 记录(“名称”:“test3”,“时间戳”:“2013-09-14 10:47:42 +0000”)
- 记录(“名称”:“test4”,“时间戳”:“2013-09-12 17:11:42 +0000”)
- 记录(“名称”:“test5”,“时间戳”:“2013-09-12 19:52:42 +0000”)
知道我想在 UITableView 中显示它们。没有部分也可以正常工作:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[...]
NSManagedObject *record = [self.records objectAtIndex:indexPath.row];
cell.recordNameLabel.text = [record valueForKey:@"name"];
return cell;
}
但现在我想用时间戳值将记录分开。所以我的想法是创建一个名为 sorted Records 的新 NSMutableArray,结构如下:
-
记录
-
日(2013-09-15)
- 记录(“名称”:“test1”,“时间戳”:“2013-09-15 12:34:35 +0000”)
-
日(2013-09-14)
- 记录(“名称”:“test2”,“时间戳”:“2013-09-14 11:21:42 +0000”)
- 记录(“名称”:“test3”,“时间戳”:“2013-09-14 10:47:42 +0000”)
-
日(2013-09-12)
- 记录(“名称”:“test4”,“时间戳”:“2013-09-12 17:11:42 +0000”)
- 记录(“名称”:“test5”,“时间戳”:“2013-09-12 19:52:42 +0000”)
-
如何将记录分组/分离到我的排序结构?
感谢您的帮助。
【问题讨论】:
-
你的时间戳是字符串还是 NSDate 对象?
标签: objective-c uitableview nsmutablearray sections