【问题标题】:NSSortDescriptor with an array in an objectNSSortDescriptor 与对象中的数组
【发布时间】:2014-11-06 12:03:56
【问题描述】:

我想按存储在对象数组中的值对 NSMutableArray 进行排序 :)

为了更好地了解我已经包含了数组。我想按时间排序(starttijd)

使用 NSSortDescriptor,我设法按状态 url 排序,而不是按时间排序。

这是我当前的排序代码:

NSSortDescriptor *sortDescriptor; sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"starttuhd" 升序:是]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

    sortedarray = [alleitems sortedArrayUsingDescriptors:sortDescriptors];
    NSLog(@"Sorted array: %@", sortedarray);

【问题讨论】:

  • 如果一个对象在custom_fields 内有多个对象,但starttijd 日期不同怎么办?应该挑选什么进行分类?
  • 你的实际排序代码是什么?
  • 永远只有1个starttijd

标签: ios sorting nsmutablearray nssortdescriptor


【解决方案1】:

首先,如果数组中只有 1 个 starttijd,那为什么它是一个数组?

不管怎样,你可以试试这个:

NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"@max.starttuhd" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
sortedarray = [alleitems sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"Sorted array: %@", sortedarray);

基本上,@max 是 KVC 集合运算符之一。由于它解析为数组中的单个元素,因此它可能会起作用。

【讨论】:

    猜你喜欢
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2015-10-06
    • 2012-06-26
    • 1970-01-01
    相关资源
    最近更新 更多