在 UITableView 上显示重新排序控件时启用滑动删除

Posted

技术标签:

【中文标题】在 UITableView 上显示重新排序控件时启用滑动删除【英文标题】:Enabling Swipe-to-delete while showing reorder controls on UITableView 【发布时间】:2009-09-17 00:23:16 【问题描述】:

我希望允许重新排序 UITableViewCells 并通过滑动删除,但不能通过红色删除圈。

- (void)loadView

    [super loadView];
    [table setEditing:YES animated:NO];


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

    if (editingStyle == UITableViewCellEditingStyleDelete) 
        // Perform delete here
    


- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath

    // Perform move here


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

    return UITableViewCellEditingStyleDelete;


- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

    return YES;

此外,我尝试禁用编辑模式并调用-[UITableViewCell setShowsReorderControl:YES],但没有成功。

(来源:booleanmagic.com)

【问题讨论】:

是的,我知道。 “链接帐户”功能不起作用。阻力最小的路径是创建一个新帐户并孤立临时帐户。 【参考方案1】:

我认为您必须进行一些自定义触摸事件拦截。

英文: 如果手指移动,x 距离,水平跨单元格,仅在该单元格中,则显示删除控件。

不知道如何关闭左边的圆圈,但我确实认为这是一个类似于“显示重新排序控制”的属性

【讨论】:

不幸的是,似乎无法以编程方式显示删除确认(显示DeleteConfirmation 是只读的)。现在我让重新排序控件可见,但最终可能会拦截触摸并手动显示自定义删除按钮。

以上是关于在 UITableView 上显示重新排序控件时启用滑动删除的主要内容,如果未能解决你的问题,请参考以下文章

如何使用删除按钮在 UITableView 中显示重新排序控件

UITableViewCell 自定义重新排序控件

在没有重新排序控制的情况下重新排序 UITableView

如何在 ios 7 上更改重新排序控制图像

重新排序 UITableView 单元格并跟踪索引

重新排序 UITableView 行时,详细视图未更新