在ios7中删除TableView的最后一行时出现动画问题 [英] problems with animation when deleting the last row of a TableView in ios7
问题描述
我在 tableView
中删除我(仅)部分的最后一行时遇到了一些问题。任何其他行都可以正常工作,但如果我在任何时候删除我的 tableView
底部的行(不仅仅是当它的最后一行),那么动画很奇怪laggy。它看起来不对劲。我也注意到改变动画类型并没有做任何事情。当行滑到顶部并消失时,动画始终是。将其更改为 UITableViewRowAnimationFade
或其他不做任何事情。
I'm having some issues when deleting the last row of my (only) section in my tableView
. Any other row works fine, but if I delete the row at the bottom of my tableView
at any time (not just when its the last one left) the animation is very strange and laggy. It just doesn't look right. I've also noticed that changing the animation type doesn't do anything. The animation is always when the row slides up to the top and disappears. Changing it to UITableViewRowAnimationFade
or another doesn't do anything.
这是我的代码
//For the edit barButtonItem in my storyboard
- (IBAction)editButtonPressed:(id)sender {
//enter editing mode
if ([self.editButton.title isEqualToString:@"Edit"]) {
[self setEditing:YES animated:YES];
self.editButton.title = @"Done";
} else {
[self setEditing:NO animated:YES];
self.editButton.title = @"Edit";
}
}
//Editing the tableView. The user can only delete rows, not add any
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Handle the data source and backend first, then the tableView row
PFRelation *hasFavorites = [self.currentUser relationforKey:@"hasFavorites"];
[hasFavorites removeObject:[self.favorites objectAtIndex:indexPath.row]];
[self.favorites removeObjectAtIndex:indexPath.row];
//It is set to fade here, but it only ever does the top animation
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
//save to the backend
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
} else {
NSLog(@"%@ %@", error, error.userInfo);
}
}];
}
}
我看过我能找到的每个答案没有运气。我在 tableview
的 numberOfSections
中返回1,因为我只想要一个部分,我应该能够拥有0部分中的行,所以我认为这不是问题。
I've looked at every answer I can find with no luck. I return 1 in my numberOfSections
in tableview
because I only ever want one section, and I should be able to have 0 rows in a section, so I don't think that's the problem.
推荐答案
它是ios7的一个错误.. tablerow动画坏了!
我的修复是在tableViewRowAnimation之前fadeOut单元格。
Its a bug of ios7.. the tablerow animations are broken! My fix was to fadeOut the cell right before the tableViewRowAnimation..
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// hide cell, because animations are broken on ios7
double iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (iosVersion >= 7.0 && iosVersion <= 8.0) {
[tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
}
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationMiddle];
}
这篇关于在ios7中删除TableView的最后一行时出现动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!