i want to sort my Data in my Tableview. I have UIButtons with IBAction to call the sort.
I have created a string which contains the sortKey. I am setting the the key and call the fetchedResultsController again, to sort the tableview.
Problem is, fetchedResultsController method is not called and the sorting doesnt work.
here is my code:
- (IBAction) actionSortCardColor:(id) sender {
XLog(@"");
sortString = @"colorOrder";
[self fetchedResultsController];
[self actionRemoveSortView:sender];
}
Here my fetchedResultsController method:
- (NSFetchedResultsController *)fetchedResultsController
{
[...]
NSPredicate *inboxPred = [NSPredicate predicateWithFormat:@"archived == 0"];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
[fetchRequest setPredicate:inboxPred];
XLog(@"sortString: %@", sortString);
if (sortString == nil) {
sortString = [[NSString alloc] initWithString:@"sortingOrder"];
}
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"setTitle" ascending:YES] autorelease];
NSSortDescriptor *sortDescriptor2 = [[[NSSortDescriptor alloc] initWithKey:sortString ascending:YES] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor, sortDescriptor2, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
[...]
}
Where is it that you let the table view know about these changes? You’ll need to reload the data for your table view instance
[tableView reloadData];When you set the __fetchedResultsController to nil, it cannot update the UITable view with any changes because it isn’t in scope.