首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用swipe to delete时的行删除动画问题

使用swipe to delete时的行删除动画问题
EN

Stack Overflow用户
提问于 2013-12-26 05:51:26
回答 3查看 608关注 0票数 0

我正在我的一个使用自定义表格视图单元格的表格上实现卷帘删除功能。我面临的问题是,当我点击“删除”按钮时,我看到一个奇怪的转换,而单元格正在被删除。

下面是我在"commitEditingStyle“中的代码,还可以看到我在删除行时捕获的附加屏幕截图。

附言:我已经尝试了所有类型的行移除动画样式,但没有运气。

代码语言:javascript
运行
复制
- (void)tableView:(UITableView *)iTableView commitEditingStyle:(UITableViewCellEditingStyle)iEditingStyle forRowAtIndexPath:(NSIndexPath *)iIndexPath {
    if (iEditingStyle == UITableViewCellEditingStyleDelete && iTableView == self.temporaryCartTable) {
        if (self.temporaryCartTable.frame.size.height == kMyAppCartTableViewExpandedHeight) {

            [self.temporaryCartTable beginUpdates];
            [self.temporaryCartTable deleteRowsAtIndexPaths:[NSArray arrayWithObjects: iIndexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];

            MyAppCartInfo *aMyAppCartInfo = [self cart];

            if (([[aMyAppCartInfo.tempProducts allKeys] count] > iIndexPath.row) && [aMyAppCartInfo.tempProducts containsObjectForKey:[[aMyAppCartInfo.tempProducts allKeys] objectAtIndex:iIndexPath.row]]) {
                [aMyAppCartInfo.tempProducts removeObjectForKey:[[aMyAppCartInfo.tempProducts allKeys] objectAtIndex:iIndexPath.row]];
            }

            [self.temporaryCartTable endUpdates];
        }
    }
}

- (BOOL)tableView:(UITableView *)iTableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return (iTableView == self.temporaryCartTable) ? YES : NO;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)iTableView editingStyleForRowAtIndexPath:(NSIndexPath *)iIndexPath {
    return UITableViewCellEditingStyleDelete;
}

- (CGFloat)tableView:(UITableView *)iTableView heightForRowAtIndexPath:(NSIndexPath *)iIndexPath {

    if (iTableView == self.temporaryCartTable) {
        if (self.isTempCartCell)
            return 92.0;
        else
            return 58.0;
    } else {
        return 58.0;
    }
}

EN

回答 3

Stack Overflow用户

发布于 2013-12-26 06:00:37

将以下方法实现添加到UITableViewDelegate

代码语言:javascript
运行
复制
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
          editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return UITableViewCellEditingStyleDelete;
}
票数 0
EN

Stack Overflow用户

发布于 2014-03-26 20:45:09

使用[self.temporaryCartTable setRowHeight:xxx]而不是使用委派rowHeightAtIndexPath。在删除行并且表中没有其他行之后,委托将不会被调用,您的表视图的行高将由其属性检索(因此为默认高度)。另外,从委托中使用此方法会影响性能。

票数 0
EN

Stack Overflow用户

发布于 2017-12-06 16:07:11

如果其他人也有这种情况,在我的例子中的问题是heightForRowAtIndexPath:,当单元格有动态大小删除动画行为奇怪。在我的案例中,解决方案是使用不同的方法,而不是花费时间进行调查。但您可以对其进行测试并查看结果。为单元格指定固定高度:

代码语言:javascript
运行
复制
self.tableView.rowHeight = Constant;

注释掉heightForRowAtIndexPath:。动画现在应该没问题了。

我知道这不是解决方案,但仍然可以帮助别人。

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

https://stackoverflow.com/questions/20777056

复制
相关文章

相似问题

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