【问题标题】:convert NSArray into NSSortDescriptor将 NSArray 转换为 NSSortDescriptor
【发布时间】:2013-11-22 12:10:12
【问题描述】:

我是 iOS 新手。我有一条警告消息,但我无法解决:) 我有以下代码:

NSSortDescriptor *sortDescriptorFirst = [NSSortDescriptor sortDescriptorWithKey:@"test" ascending:YES];
NSSortDescriptor *descriptor=[NSArray arrayWithObjects:sortDescriptorFirst,nil];
NSArray *sortedArray =[sections sortedArrayUsingDescriptors:@[descriptor]];

在第 2 行我有一个警告:

Incompatible pointer types initializing NSSortDescriptor with an expression of NSArray

如何解决?

【问题讨论】:

    标签: ios objective-c nsarray nssortdescriptor


    【解决方案1】:

    你已经在第一行创建了 NSSortDescriptor,所以你不需要第二行:

    NSSortDescriptor *sortDescriptorFirst = [NSSortDescriptor sortDescriptorWithKey:@"test" ascending:YES];
    NSArray *sortedArray =[sections sortedArrayUsingDescriptors:@[sortDescriptorFirst]];
    

    【讨论】:

      猜你喜欢
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多