0

I have loaded multiple datas into tableview like below diagrams. I need to create button first click to show all the data's ascending order A to Z. like below figure (1)

----------------------------------  
  A         14           30
----------------------------------  
  z         20           10
----------------------------------  

Button second click to show all the data decending order Z to A. like below.

----------------------------------  
  Z        20           10
----------------------------------  
  A        14           30
----------------------------------

For some reason I have loaded multiple column values into separate NSMutableArray for tableview.

    NSDictionary *alertArray = [notificationdata objectForKey:@"response"];
    NSArray *sortedKeys = [[alertArray allKeys] 
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

    // Array_One
    NSMutableArray *one = [[NSMutableArray alloc]init];

    // Array_Two
    NSMutableArray *two = [[NSMutableArray alloc]init];

   for (keys in sortedKeys) {

        [one addObject:[alertArray objectForKey:keys][@"name"]];
        [two addObject:[alertArray objectForKey:keys][@"values"]];

    }
  1. How to show descending order names?
  2. How to show total reverse order no's (second column)?
AnswerMe
  • 189
  • 1
  • 1
  • 10

1 Answers1

1

TRY THIS..

NSDictionary *alertArray = [notificationdata objectForKey:@"response"];
NSArray *sortedKeys = [[alertArray allKeys] 
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
// Array_One
NSMutableArray *one = [[NSMutableArray alloc]init];

// Array_Two
NSMutableArray *two = [[NSMutableArray alloc]init];

one  = [[[alertArray allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@“name” ascending:NO]]] mutableCopy];
two = [[[alertArray allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@“value” ascending:YES]]] mutableCopy];
Jincy Sam
  • 421
  • 2
  • 11