title: Sort UITableview in objective c with dates descending NSDictionary
body: <p>Thank you for looking into my question here.  I am trying to get uitableview sectioned by dates in descending order. I get the data from the sqllite order by datefield desc.   But whatever I do the dates are displayed in ascending order. I have the following set of data that comes out of the db and in this order:</p>
  
  <pre><code>ID BookName DateRead
  1  ABC      19-10-2011
  2  ABZ      27-06-2011
  3  ABD      28-05-2011  
  </code></pre>
  
  <p>I would like the data to appear like the following</p>
  
  <pre><code>19-10-2011  
  ABC 
  27-06-2011  
  ABZ
  28-05-2011  
  ABD  
  </code></pre>
  
  <p>but no matter what I am trying I am getting the data returned as below:<br>
      19-10-2011<br>
      ABC<br>
      28-05-2011<br>
      ABZ<br>
      27-06-2011<br>
      ABD</p>
  
  <p>Here is the complete list of code that I am using:
  .h file</p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
      @interface BookHistoryViewController : UITableViewController {
          NSArray *books;
          NSMutableDictionary *sections; 
      }
      @property (nonatomic,retain) NSArray *books;
      @property (nonatomic,retain) NSMutableDictionary *sections;
  
  @end
  </code></pre>
  
  <p>Here is my .m file</p>
  
  <pre><code>- (void)viewDidLoad {
  
      TestAppDelegate *appDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate];
  
  
     [Book getInitialDataToDisplay:[appDelegate getDBPath]];
  
  
  
      self.books = [NSMutableArray arrayWithArray:appDelegate.bookArray];
  
  
      self.sections = [[NSMutableDictionary alloc] init];
  
  
  
      BOOL found;
  
      // Loop through the books and create our keys
  
      for (NSDictionary *book in books)
      {    
  
  
          NSString *c = [book valueForKey:@"DateRead"];
  
          found = NO;
  
          for (NSString *str in [self.sections allKeys])
          {
              if ([str isEqualToString:c])
              {
                  found = YES;
              }
          }
  
          if (!found)
          {     
              [self.sections setValue:[[NSMutableArray alloc] init] forKey:c];
          }
      }
  
      // Loop again and sort the books into their respective keys
      for (NSDictionary *book in self.books)
      {
          [[self.sections valueForKey:[book valueForKey:@"DateRead"]] addObject:book];
      }    
  
      // Sort each section array
      for (NSString *key in [self.sections allKeys])
      {
          [[self.sections objectForKey:key] sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"DateRead" ascending:NO]]];
      }    
  
      [super viewDidLoad];
  
  }
  
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
  {
      return [[self.sections allKeys] count];
  }
  
  - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  {    
      return [[[self.sections allKeys] sortedArrayUsingSelector:@selector(compare:)] objectAtIndex:section];
  
  
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
  {
      return [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(compare:)] objectAtIndex:section]] count];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
      }
  
      NSDictionary *book = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(compare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  
      cell.textLabel.text = [book valueForKey:@"title"];    
  
  
      return cell;
  
  
  }
  </code></pre>