Xcode: Sorting tableview sections false

I have a problem with the tableview section order. Data come from Json call.

Now i have a NSMutablDictonary with first key as date (for sections). This order by date are fine.

The tableview sort the section not by NSMutablediconary. Why ?

The Dictionary looks like:

2017-06-29 = {
             title = retort,
             name = betertertar
             }
2017-06-30 = {
              title = erterte,
              name = bertertar
             }
2017-07-01 = {
              title = dsfsff,
              name = sdfsdsdf
             }


2017-06-28 22:51:20.848[59131:33504414] numberOfSectionsInTableView: 3
2017-06-28 22:51:20.848[59131:33504414] -->   numberOfRowsInSection (section): 2
2017-06-28 22:51:20.848[59131:33504414] -->   numberOfRowsInSection (section): 0
2017-06-28 22:51:20.848[59131:33504414] -->   numberOfRowsInSection (section): 1

See image

How can i correct order ?

Miner Asked on June 29, 2017 in General Stack.
Add Comment


  • LATEST ANSWERS

  • 1 Answer(s)
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MM/dd/yyyy"];
    NSArray *sortedArray = [yourArray sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
        NSDate *d1 = [df dateFromString: obj1];
        NSDate *d2 = [df dateFromString: obj2];
        return [d1 compare: d2];
    }];
    
    
    
    
    Default Answered on June 29, 2017.
    Add Comment

    Write your answer

    By posting your answer, you agree to the privacy policy and terms of service.