0

I have got an array of strings which i sort using the method

[TableViewPopoverList sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

The first part of these strings is a number, however for example if string1 = "16 Ag....." and string2 = "8 Ag...." it sorts it as string1 then string2, obviously it sees the 1 and puts it before the 8, What i want to do is have it so it sees the entire number so it sorts string2 then string1.

What is the easiest way of doing this.

Thanks

4

1 回答 1

4

这样做...

[TableViewPopoverList sortUsingComparator:^(NSString *obj1, NSString *obj2) {
    return [obj1 compare:obj2 options:(NSCaseInsensitiveSearch | NSNumericSearch)];
}];

这使用compare:options:方法 onNSString并且该NSNumericSearch选项会将数字与实际数字进行比较。

于 2013-09-18T16:15:03.323 回答