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)?
4

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome Working now. Thank you but How to change numbers column ?@Jincy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.