Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort alphabetically a UITableView Sectioned?

I have a sectioned UITableView with 3 categories. I'm using this code:

NSArray *arrayOne = [NSArray arrayWithObjects: @"one", @"two", "three", "four", nil];
    NSDictionary *dictOne = [NSDictionary dictionaryWithObject:arrayOne forKey:@"Elements"];

for each category.

How can i sort them alphabetically? I've read some answers here but i didn't found out anything.

If i use the code in this answer Method for sorting custom objects alphabetically in UITableView it doesn't work. i have the code:

[listObjects addObject:dictOne];

and if i put

[listOfTitles sortUsingDescriptors:[NSArray arrayWithObject:titleSorter];

It doesn't work.

Any help appreciated

like image 762
Phillip Avatar asked Jan 20 '23 03:01

Phillip


1 Answers

NSArray *arrayOne = [NSArray arrayWithObjects: @"one", @"two", "three", "four", nil];

NSArray *sortedArray = [arrayOne sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];


NSDictionary *dictOne = [NSDictionary dictionaryWithObject:sortedArray forKey:@"Elements"];
like image 153
Vijay-Apple-Dev.blogspot.com Avatar answered Jan 29 '23 11:01

Vijay-Apple-Dev.blogspot.com