UITableViewRowAnimationFade not working

So, this question follows from the previous problem , but I decided to publish a new question in order to maintain relevance and order.

Basically, when the following code snippet is called, there is no difference between UITableViewRowAnimationFade and UITableViewRowAnimationNone :

 - (void) setEditing:(BOOL)editing animated:(BOOL)animated { [tvController.tableView beginUpdates]; if (editing == YES) { [tvController.tableView deleteRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:UITableViewRowAnimationFade]; }else { UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone; [tvController.tableView reloadRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:animation]; [tvController.tableView reloadSectionIndexTitles]; self.navigationItem.hidesBackButton = editing; } [tvController.tableView endUpdates]; } 

I really appreciate any help. It still enters editing mode, but does not animate it, depsite YES is transferred to animated.


EDIT: The animation works fine when I actually delete everything using the following code:

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *stuff = [documentsPath stringByAppendingPathComponent:@"stuff.plist"]; BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:stuff]; if (fileExists) { NSMutableDictionary *propertyList = [[NSMutableDictionary alloc] initWithContentsOfFile:enteredPlaces]; [propertyList removeObjectForKey:[[settingsArray objectAtIndex:1] objectAtIndex:indexPath.row]]; [propertyList writeToFile:stuff atomically:YES]; } [[settingsArray objectAtIndex:1] removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } } 

It just does not work, when the user presses the edit button, and the table goes into edit mode, tableview is simply statically put into edit mode.

+4
source share
3 answers

I have the same scenario in my application, I ran into a similar problem. I think the below function will solve your problem:

 - (void) setEditing:(BOOL)editing animated:(BOOL)animated { [tvController.tableView setEditing:editing animated:animated]; //this LOC is added [tvController.tableView beginUpdates]; if (editing == YES) { [tvController.tableView deleteRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:UITableViewRowAnimationFade]; } else { UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone; [tvController.tableView reloadRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:animation]; [tvController.tableView reloadSectionIndexTitles]; self.navigationItem.hidesBackButton = editing; } [tvController.tableView endUpdates]; } -(void)deleteRecord:(NSInteger)recordNo:(NSInteger)sectionNo:(BOOL)isEditMode:(BOOL)isAnimate { if(isEditMode){ NSIndexPath *indexP=[NSIndexPath indexPathForRow:recordNo inSection:sectionNo]; [tvController.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexP, nil] withRowAnimation:UITableViewRowAnimationLeft]; } else { if(isAnimate) [tvController.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexP, nil] withRowAnimation:UITableViewRowAnimationFade]; else [tvController.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexP, nil] withRowAnimation:UITableViewRowAnimationNone]; [tvController.tableView reloadSectionIndexTitles]; self.navigationItem.hidesBackButton = editing; } [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(reload) userInfo:nil repeats:NO]; } -(void)reload { [table reloadData]; } 
0
source
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [db DeleteData:[NSString stringWithFormat:@"%d",indexPath.row]]; [data removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade]; } } 
0
source

If the only thing that annoys you is the fact that the removal does not disappear, because you are expecting something that the interface does not provide.

you mentioned that you know that individual cells may not be editable, and this is the standard way to do this. the mechanism simply does not expect to use a UITableViewDataSource to provide information about what to display (or, in your case, what is in the mutable data), simply by clicking the edit / end button.

Trying to combine these two, you confuse the animation that should happen.

perhaps the best thing you can do is something like the following (and the animation duration and length can be 0, as you request a separate animation in the tableView), which will call your animation after the animation, opens the edit mode.

 - (void) setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated]; // possibly not necessary depending upon your class hierarchy [tvController.tableView setEditing:editing animated:animated]; [UIView animateWithDuration:0.25 delay:0.05 options:UIViewAnimationCurveLinear animations:^{ [tvController.tableView beginUpdates]; if (editing == YES) { [tvController.tableView deleteRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:UITableViewRowAnimationFade]; } else { UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone; [tvController.tableView reloadRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:animation]; [tvController.tableView reloadSectionIndexTitles]; self.navigationItem.hidesBackButton = editing; } [tvController.tableView endUpdates]; } completion:nil]; } 
0
source

All Articles