我正在使用以下NSSortDescriptor代码来对数组进行排序。目前我是按照价格排序,但希望也能限制价格。例如,是否可以按价格排序但只显示小于100的价格?
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey: @"price" ascending: YES];
NSMutableArray *sortedArray = (NSMutableArray *)[self.displayItems
sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortDescriptor]];
[self setDisplayItems:sortedArray];
[self.tableView reloadData];
NSArray
强制转换为NSMutableArray
。请使用[array mutableCopy]
。 - Sebastian