我有一个NSTable
填充数据。我使用以下代码对列进行了排序。问题是当我想要数字时它会按字母顺序对数字列进行排序。
(1,100,101,2,20,21,3,30,31................)
我将数据输入为数字(@1, @2, @3)
而不是字符串(@"1", @"2", @"3")
// THIS WILL SORT ALL COLUMNS //
- (void)tableView:(NSTableView *)tableView mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn
{
NSTableColumn *NumberColumn = [tableView tableColumnWithIdentifier:@"No."];
NSSortDescriptor *NumberSortDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"No."
ascending:YES
selector:@selector(compare:)];
[NumberColumn setSortDescriptorPrototype:NumberSortDescriptor];
NSTableColumn *CardNameColumn = [tableView tableColumnWithIdentifier:@"Card Name"];
NSSortDescriptor *CardNameSortDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"Card Name"
ascending:YES
selector:@selector(compare:)];
[CardNameColumn setSortDescriptorPrototype:CardNameSortDescriptor];
NSTableColumn *TypeColumn = [tableView tableColumnWithIdentifier:@"Type"];
NSSortDescriptor *TypeSortDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"Type"
ascending:YES
selector:@selector(compare:)];
[TypeColumn setSortDescriptorPrototype:TypeSortDescriptor];
NSTableColumn *RarityColumn = [tableView tableColumnWithIdentifier:@"Rarity"];
NSSortDescriptor *RaritySortDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"Rarity"
ascending:YES
selector:@selector(compare:)];
[RarityColumn setSortDescriptorPrototype:RaritySortDescriptor];
NSTableColumn *UnlimitedColumn = [tableView tableColumnWithIdentifier:@"Unlimited"];
NSSortDescriptor *UnlimitedSortDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"Unlimited"
ascending:YES
selector:@selector(compare:)];
[UnlimitedColumn setSortDescriptorPrototype:UnlimitedSortDescriptor];
NSTableColumn *FirstEditionColumn = [tableView tableColumnWithIdentifier:@"1st Edition"];
NSSortDescriptor *FirstEditionSortDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"1st Edition"
ascending:YES
selector:@selector(compare:)];
[FirstEditionColumn setSortDescriptorPrototype:FirstEditionSortDescriptor];
}
- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray
*)oldDescriptors
{
[BaseSet sortUsingDescriptors: [tableView sortDescriptors]];
[tableView reloadData];
}