在ios7中删除TableView的最后一行时出现动画问题

Sto*_*123 12 editing tableview ios

删除我的(仅)部分的最后一行时,我遇到了一些问题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);
            }
        }];
    }
}
Run Code Online (Sandbox Code Playgroud)

我看过每一个没有运气的答案.我在我的numberOfSectionsin中返回1 tableview因为我只想要一个部分,并且我应该能够在一个部分中有0行,所以我认为这不是问题所在.

cal*_*kus 19

它是ios7的一个bug ..桌面动画被破坏了!我的修复是在tableViewRowAnimation之前fadeOut单元格.

- (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];
}
Run Code Online (Sandbox Code Playgroud)

  • 这个错误似乎在iOS 8上得到修复,因此可能值得添加"<8.0"检查. (2认同)