Lou*_*uie 4 iphone sdk iphone-sdk-4.1
我试图将一系列价格从低到高排序.我有它的工作,但不是我想要的方式.长话短说,分拣机按顺序排列数字:100 10900 200 290
而不是像这样排序
100 200 290 10900
这是我的代码我这样做.
-(void)filterPriceLowHigh {
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"ListPrice"
ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [app.vehiclesArrayToDisplay
sortedArrayUsingDescriptors:sortDescriptors];
[app.vehiclesArrayToDisplay removeAllObjects];
[app.vehiclesArrayToDisplay addObjectsFromArray:sortedArray];
}
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我需要做什么吗?提前致谢.
Ole*_*ann 10
像这样创建排序描述符:
sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"ListPrice"
ascending:YES
comparator:^(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2179 次 |
| 最近记录: |