我在删除我的tableView
中唯一一个section的最后一行时遇到了问题。其他行都正常工作,但如果我随时删除底部的行(不仅是当它是最后一个时),动画会非常奇怪和卡顿。它看起来就不对。我还注意到更改动画类型没有任何效果。动画总是让行向上滑动并消失。将其更改为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行,所以我认为这不是问题所在。