I have fetched some records from core data, and presented it in a table view. All of these records have 11 properties. Now in my tableview presentation, on header I have added a button for all of these properties. On clicking of the button, I want to sort the records on the basis of that property. I tried using sort descriptor, but it doesn't work. My code is like this:-
- (IBAction)sortButton:(id)sender {
// tags are from 100 to 111
UIButton *sortButton = (UIButton*)sender;
NSString *sortDescriptorKey = nil;
// create sort descriptor key according to the tag value
if (sortButton.tag == 100 ) sortDescriptorKey = [NSString stringWithString:@"reportID "];
....
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortDescriptorKey ascending:YES];
[self.recordArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
[self.tableView reloadData];
}
But, this code does not change any ordering at all. Am I missing anything, or is there is another way of doing it.