So I've got a button on my UITableView
that turns on and off a filter, that filters by a BOOL
called isLiked
. I can display all results, or just the ones designated as liked. I can tap on any cell and go into a detail page where I can flip that BOOL
on or off.
If I'm in the liked-fitered list and I tap one, then turn its favourite status to off, then go Back to the liked-filtered once more, it hasn't disappeared. If I flip the filter off and on again, that entry disappears.
I'd like that change to occur as soon as I come back out of that view, rather than needing to turn the filter on and off for it to take effect. How can I achieve that? Some relevant code is below:
Here's the method that is called when I turn the filter on and off:
- (IBAction) filterLiked: (id) sender
{
if (isDisplayingLiked) {
// Revert to the predicate that only removes disliked entries.
[_fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"isDisliked == 0"]];
NSError *error;
if (![self.fetchedResultsController performFetch: &error]) NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
// Update the tableView and update state variables.
[self.tableView reloadData];
isDisplayingLiked = NO;
[_showLikedButton setTitle: @"Liked"];
} else {
// Revert to the predicate that only shows liked entries.
[_fetchRequest setPredicate: [NSPredicate predicateWithFormat:@"isLiked == 1"]];
NSError *error;
if (![self.fetchedResultsController performFetch: &error]) NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
// Update the tableView and update state variables.
[self.tableView reloadData];
isDisplayingLiked = YES;
[_showLikedButton setTitle: @"All"];
}
}
Here's the code that's called when I turn the Liked status on or off from within a detail view:
- (IBAction) changeLikedSwitch: (id) sender
{
UISwitch *likedSwitch = (UISwitch *) sender;
if ([likedSwitch isOn]) {
[_selectedQuote setIsLiked: [NSNumber numberWithBool: YES]];
} else {
[_selectedQuote setIsLiked: [NSNumber numberWithBool: NO]];
}
NSError *error;
if (![[[CDManager sharedManager] managedObjectContext] save:&error]) NSLog(@"Saving changes failed: %@, %@", error, [error userInfo]);
}
If you need any more code, please let me know.