I have an array of strings (names)
and i would like to sort them like how the address book on the iphone sorts them
- eg: éli -> under E
- eg: àli -> under A
- eg: 4li -> under #
any suggestions?
I have an array of strings (names)
and i would like to sort them like how the address book on the iphone sorts them
any suggestions?
all lies within the
compare:
method you will use as the selector of your sorting method and more importantly with theNSDiacriticInsensitiveSearch
option.Now you need to add the
compareTheAddressBookWay:
method in a category!!Important!!:
Using
sortedArrayUsingSelector:
will be compliant for iOS up to 2.0while using
sortedArrayUsingComparator:
will ONLY work for iOS 4 and above.You need to perform a diacritic insensitive comparison against the strings.
NSString
has acompare:options:
method with an option ofNSDiacriticInsensitiveSearch
.Edit:
Here is a full example that will section the results based on the first character diacritic insensitive. I put in a dictionary so you would need to keep track of the sorted keys on your own to display properly.