开发者

Sorting data numerically from a plist dictionary in a UIPicker

开发者 https://www.devze.com 2023-03-26 12:29 出处:网络
I\'m using the following code to sort the results in a UIPicker. The results are coming randomly because I am usi开发者_如何学运维ng a dictionary / plist to store the data.

I'm using the following code to sort the results in a UIPicker. The results are coming randomly because I am usi开发者_如何学运维ng a dictionary / plist to store the data.

NSArray *components = [self.dobRangesDict allKeys];
NSArray *sorted = [components sortedArrayUsingSelector: @selector(compare:)];
self.dates = sorted;

this sorts the data, but I'm looking to sort the data numerically. Any ideas how I might go about accomplishing this?

thanks for any help.


There are a couple of options here.

My personal choice is to use [components sortedArrayUsingComparator:^(NSString *a, NSString *b) { return [a compare:b options:NSNumericSearch]; }]

0

精彩评论

暂无评论...
验证码 换一张
取 消