我的NSArray
包含NSDictionary
实例,在字典中我有订单编号。我想让它们按降序排序。但这不是排序。
我已经尝试过此代码
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"orderid" ascending:FALSE];
[self.orderArray sortUsingDescriptors:[self.orderArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
和这段代码:
[self.orderArray sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"orderid" ascending:NO]]];
但这没有用。
这是日志
orders : (
{
orderid = 6739;
},
{
orderid = 6740;
},
{
orderid = 6745;
},
{
orderid = 6746;
},
{
orderid = 6748;
},
)
我同意@HotLicks此代码必须有效。您确定排序代码和日志之间没有代码。如果有,请添加。
我看到的唯一问题是您已在[self.orderArray sortUsingDescriptors:[self.orderArray arrayWithObject:sortDescriptor]];
此行中添加了阵列名称而不是NSArray 。
像这样做 :
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"orderid" ascending:FALSE];
[self.orderArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; //Change in this line
[sortDescriptor release];
NSLog(@"self.orderArray : %@",self.orderArray);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句