UITableView 禁用滑动删除,但在编辑模式下仍有删除? [英] UITableView disable swipe to delete, but still have delete in Edit mode?

查看:23
本文介绍了UITableView 禁用滑动删除,但在编辑模式下仍有删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要类似闹钟应用的东西,你不能滑动删除行,但你仍然可以在编辑模式下删除行.

I want something similar as the Alarm app, where you can't swipe delete the row, but you can still delete the row in Edit mode.

当注释掉 tableView:commitEditingStyle:forRowAtIndexPath: 时,我禁用了滑动删除并且在编辑模式下仍然有删除按钮,但是当我按下删除按钮时会发生什么.叫什么?

When commented out tableView:commitEditingStyle:forRowAtIndexPath:, I disabled the swipe to delete and still had Delete button in Edit mode, but what happens when I press the Delete button. What gets called?

推荐答案

好吧,事实证明这很容易.这就是我为解决这个问题所做的:

Ok, it turns out to be quite easy. This is what I did to solve this:

Objective-C

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Detemine if it's in editing mode
    if (self.tableView.editing)
    {
        return UITableViewCellEditingStyleDelete;
    }

    return UITableViewCellEditingStyleNone;
}

斯威夫特 2

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
    if tableView.editing {
         return .Delete
    }

    return .None
}

斯威夫特 3

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    if tableView.isEditing {
        return .delete
    }

    return .none
}

你仍然需要实现 tableView:commitEditingStyle:forRowAtIndexPath: 来提交删除.

You still need to implement tableView:commitEditingStyle:forRowAtIndexPath: to commit the deletion.

这篇关于UITableView 禁用滑动删除,但在编辑模式下仍有删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆