【发布时间】:2014-01-25 10:26:18
【问题描述】:
我在删除tableView 中(唯一)部分的最后一行时遇到了一些问题。任何其他行都可以正常工作,但是如果我随时删除tableView 底部的行(不仅仅是在它离开的最后一行),动画就会非常奇怪和滞后。只是看起来不太对。我还注意到更改动画类型没有任何作用。动画始终是当行滑到顶部并消失时。将其更改为 UITableViewRowAnimationFade 或其他不会做任何事情。
这是我的代码
//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 行,所以我认为这不是问题。
【问题讨论】:
-
在扯掉头发之前,您应该尝试使用一些本机应用程序来重现这一点(Notes.app 是一个尝试的好地方)。如果您有一个小于屏幕高度的表格并且您删除了最后一行,则该行会停止,然后被删除。没有动画。我猜这是操作系统本身的一个错误。
-
您正在设备上进行测试,对吧?
-
@GuyKogus 是的,设备和模拟器上的行为相同。
-
@mikekavouras,很有趣。时钟应用确实表现出相同的行为。这是操作系统本身的一个错误。太糟糕了。