首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >删除TableView在ios7中的最后一行时动画出现的问题

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

Stack Overflow用户
提问于 2014-01-07 16:23:32
回答 4查看 8.1K关注 0票数 12

在删除我的tableView (仅)部分的最后一行时,我遇到了一些问题。任何其他行都可以正常工作,但是如果我在任何时候删除tableView底部的行(不只是在最后一个行离开的时候),动画就非常奇怪和滞后。只是看起来不太对劲。我还注意到,改变动画类型没有任何作用。动画总是当行滑到顶部并消失时。将其更改为UITableViewRowAnimationFade或另一个并不能起到任何作用。

这是我的密码

代码语言:javascript
复制
//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中的tableview中返回1,因为我只想要一个节,而且我应该能够在一个节中有0行,所以我不认为这是问题所在。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-01-07 19:38:03

这是ios7的一个错误..。桌面动画坏了!我的解决办法是在fadeOut之前的tableViewRowAnimation.

代码语言:javascript
复制
- (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];
}
票数 19
EN

Stack Overflow用户

发布于 2014-09-18 11:13:06

下面是我发现的一个很好的解决方案,它建立在jaydee3 3的回答之上:

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ 
     if (editingStyle == UITableViewCellEditingStyleDelete) {
          // hide cell, because animations are broken on ios7
          double iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];

          if (iosVersion >= 7.0 && iosVersion <= 8.0) {
              // Animating the cell's alpha change gives it a smooth transition
              // Durations > .17 show the glitch on iPad, phone looks nice up to 0.3
              [UIView animateWithDuration:0.17 animations:^(void) {
                  [tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
              }];
          }
          NSArray *deleteIndexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];

          // UITableViewRowAnimationFade looks nice with the animation imho
          [tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
     }
}
票数 3
EN

Stack Overflow用户

发布于 2014-01-27 12:18:57

我也有同样的窃听器。我只是在UITableViewRowAnimationMiddle上更改了动画类型,并将其全部修复。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20976700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档