I've been able to figure this out, mostly. Here's what I've come up with:
- (IBAction)completeSwitchTapped:(id)sender {
UIView *currentSuperview = [sender superview];
while (![currentSuperview isKindOfClass:[UITableViewCell class]] && [currentSuperview superview] != nil) {
currentSuperview = [currentSuperview superview];
}
NSIndexPath *indexPath = [self.itineraryTableView indexPathForCell:(UITableViewCell *)currentSuperview];
NSIndexPath *newIndexPath = [[NSIndexPath alloc] init];
switch (indexPath.section) {
case kIncompleteActivitiesSection: {
Activity *theActivity = [[_activitiesArray filteredArrayUsingPredicate:_predIncomplete] objectAtIndex:indexPath.row];
[[[_activitiesArray filteredArrayUsingPredicate:_predIncomplete] objectAtIndex:indexPath.row] setValue:@YES forKey:@"isComplete"];
unsigned long newIndex = [[_activitiesArray filteredArrayUsingPredicate:_predComplete] indexOfObject:theActivity];
newIndexPath = [NSIndexPath indexPathForRow:newIndex inSection:kCompleteActivitiesSection];
[self.itineraryTableView beginUpdates];
[self.itineraryTableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
[self.itineraryTableView endUpdates];
break;
}
case kCompleteActivitiesSection: {
Activity *theActivity = [[_activitiesArray filteredArrayUsingPredicate:_predComplete] objectAtIndex:indexPath.row];
[[[_activitiesArray filteredArrayUsingPredicate:_predComplete] objectAtIndex:indexPath.row] setValue:@NO forKey:@"isComplete"];
unsigned long newIndex = [[_activitiesArray filteredArrayUsingPredicate:_predIncomplete] indexOfObject:theActivity];
newIndexPath = [NSIndexPath indexPathForRow:newIndex inSection:kIncompleteActivitiesSection];
[self.itineraryTableView beginUpdates];
[self.itineraryTableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
[self.itineraryTableView endUpdates];
break;
}
default: {
break;
}
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]];
[self.itineraryTableView reloadData];
}
I'm not sure if the run loop delay is a good choice, but it's the right timing and it looks great.