0

I am using the NSDictionary to show the data in UITableview.

And Sections is now showing like -

My Log is - NSLog(@"%@",[self.base_dictionary allKeys]);

(
"2 days ago",
"2 weeks ago",
"4 weeks ago",
"5 days ago",
"1 week ago",
Today
)

Anyone can help how i can sort it properly -

("Today","2 days ago","5 days ago","1 week ago","2 weeks ago","4 weeks ago")
ChintaN -Maddy- Ramani
  • 5,156
  • 1
  • 27
  • 48
San007
  • 762
  • 1
  • 9
  • 30
  • 2
    "I am using the NSDictionary to show the data in UITableview." That is your first mistake. If you want the rows to be ordered you should use an NS(Mutable)Array. – Hot Licks Oct 31 '14 at 17:07
  • 2
    (An NSDictionary cannot be "sorted" -- the entries are, by definition, in an undefined order.) – Hot Licks Oct 31 '14 at 17:08
  • I am using NSDictionary because - I am grouping data according to the created time and adding in NSDictionary. How can i show the NSMutableArray with section headers ? – San007 Oct 31 '14 at 19:17
  • You have an array with one element per section. That one element contains a dictionary. The dictionary contains the header info and an array of rows. Each row is a dictionary containing the info for the corresponding cell. If needed, you use a `sortWith...` function on the outermost array to maintain its sort order, but in most cases you can simply insert entries in the order they should have. – Hot Licks Oct 31 '14 at 19:21

1 Answers1

-1

Change the key that is being used from a string to a numerical string containing the value of number of days since today, i.e. "000","014","028", "128", etc. This can then be used to sort the items, you'll need to ensure you have leading zeros otherwise the sort won't work correctly.

Then when you want to display the title for the section, use a method to calculate a string representation

Flexicoder
  • 8,251
  • 4
  • 42
  • 56