Sort an array with respect to the Date in iphone sdk
I have a tableview with values loaded from a web service. Which contains date value, here is how it looks like :
"Title":"Title1",
"StartDate":"9\/15\/2011 12:00:00 AM",
"EndDate":"10\/15\/2011 12:00:00 AM".
I have done formatting using NSDateFormatter, I got the output as:
theDate: |09/22/2011|
theTime: |14:09:30 PM|
Now I need to sort the Title in the tableview with respect to the corresponding dates of each title. How can I implement that? Please share your ideas...
And I need to implement th开发者_C百科is function on a button action, that is the sorting function should be performed on a button action.
Thank you...
NSSortDescriptor* nameSorter = [[NSSortDescriptor alloc] initWithKey:@"startDate" ascending:NO];
NSMutableArray *temp = [yourArray mutableCopy];
[temp sortUsingDescriptors:[NSArray arrayWithObject:nameSorter]];
yourArray = temp;
[self.tableView reloadData];
The same goes with titles as well.
精彩评论