日期数组排序问题,iPhone sdk
我有一个包含不同日期值的数组。我使用以下代码对日期数组进行排序,完成。
combinedArr = [[NSMutableArray alloc]init];
NSInteger counts = [pbTitle count];
for (int i = 0; i < counts; i++) {
CustomObject *customobject2 = [CustomObject customObjectWithName:
[pbTitle objectAtIndex:i] andDate:[pbstartDate objectAtIndex:i]];
[combinedArr addObject:customobject2];
}
[combinedArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2)
{
return [[(CustomObject*)obj1 date]compare: [(CustomObject*)obj2 date]];
}];
NSLog(@"Results: %@", combinedArr);
现在结果在combinedArr中,我需要检查每个值与当前系统时间,并且需要加载到两个不同的数组中,并将这两个数组加载到tableView的两个部分中。我怎样才能实现它?请帮我找到解决方案。
I have an array that contains different date values. And I have used the following code to sort the date array, its done.
combinedArr = [[NSMutableArray alloc]init];
NSInteger counts = [pbTitle count];
for (int i = 0; i < counts; i++) {
CustomObject *customobject2 = [CustomObject customObjectWithName:
[pbTitle objectAtIndex:i] andDate:[pbstartDate objectAtIndex:i]];
[combinedArr addObject:customobject2];
}
[combinedArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2)
{
return [[(CustomObject*)obj1 date]compare: [(CustomObject*)obj2 date]];
}];
NSLog(@"Results: %@", combinedArr);
Now the result is in the combinedArr, I need to check the each value with current system time and need to load into two different arrays, and load these two arrays into two sections of a tableView. How can I implement that? Please help me to find a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最简单、最快(运行时间更短)的解决方案是从一开始就创建 2 个单独的数组,并分别对每个数组进行排序。
像这样:
I think that the simplest and the fastest (shorter running time) solution is to create 2 separate arrays from the beginning and sort each one separately.
Like this: