允许UITableView重新排序,但不能在编辑模式下删除,并且无论如何都允许滑动以删除

弗雷德里克

我有一个UITableView(iOS 9),我通过滑动实现了两个操作(一个是删除操作),我有一个“编辑”按钮以启用编辑模式(对行进行重新排序)

为此,我实施了

    override func setEditing(editing: Bool, animated: Bool) {

    super.setEditing(editing, animated:animated)

    if (!isInSwipeDeleteMode) {
        if (self.tableView.editing) {
            metAJourPersonnes()
            tableView.reloadData()
        }
        else {
            tableView.reloadData()
        }
    }
}

    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {

    if (indexPath.row < personnes.count) {
        return true
    } else {
        return false
    }
}

override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
    let pers = personnes[sourceIndexPath.row]
    personnes.removeAtIndex(sourceIndexPath.row)
    if (destinationIndexPath.row < personnes.count)
    {
        personnes.insert(pers, atIndex: destinationIndexPath.row)
    } else {
        personnes.append(pers)
    }
    tableView.reloadData()
}

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
    if (indexPath.row < personnes.count) {
        return .Delete
    } else {
        return .None
    }
}

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let deleteClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        print("Delete closure called")
        self.tableView(tableView, commitEditingStyle: .Delete, forRowAtIndexPath: indexPath)
    }

    let modifyClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        print("More closure called")            
        self.performSegueWithIdentifier("modifPersonne", sender: indexPath)
    }

    let deleteAction = UITableViewRowAction(style: .Default, title: "Supprimer", handler: deleteClosure)
    let modifyAction = UITableViewRowAction(style: .Normal, title: "Modifier", handler: modifyClosure)   
    return [deleteAction, modifyAction]

}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    switch editingStyle {

    case .Delete:
        // Delete in the coreData base         
        personnes.removeAtIndex(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

    default:    break
    }
}

一切工作正常,但我希望编辑模式仅适用于重新排序。我不希望出现红色减号,但我想保持滑动动作。

这可能吗?似乎在编辑模式下禁用删除确实会禁用滑动以删除手势。

rmaddy

我相信您只需更改代码就是editingStyleForRowAtIndexPath函数。.Delete当表视图未处于编辑模式时才返回

这样一来,“删除删除”仍然有效(不在编辑模式下),并且当您切换到编辑模式时,无法删除该行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在编辑模式下删除字典中的键值对?

无论如何我都无法删除文件

Rails 4删除嵌套属性,只能在创建时使用,但不能在编辑/更新时使用

允许读取和删除但不能在linux目录中创建文件?

允许用户创建文件,但不能编辑和删除它们

在UITableView的编辑模式下如何不显示“-”删除按钮?

如何在编辑模式下的UITableView中选择多行?

如何允许用户创建和删除文件/文件夹,但不能修改它们?

Samba共享权限:允许创建文件,但不允许编辑/删除

UITableview编辑模式下的删除控制按钮不起作用

防止UITableViewCell子类允许滑动删除?

在编辑模式下使用自定义滑动操作时,如何防止单元缩进?

处于“确认删除”状态并且表格处于编辑模式时,如何自定义UITableView单元格

我是Windows 7的管理员帐户,无论如何都无法删除某些文件或文件夹

精神:在开始时允许角色,但不能在中间

允许SFTP用户创建新文件,但不能修改或删除它们

更新TopicsController以允许主持人更新主题,但不能创建或删除主题

有什么方法可以允许移动具有借入元素但不能删除的容器?

无论如何,在加载XmlDocument之前是否要删除“与”号?

自定义 UITableViewCell 的内容在编辑模式下被删除按钮重叠

允许对工作项目发表评论,但不能编辑

无论如何都无法安装GRUB

无论如何,函数都返回 None

如何在编辑时更改iPhone UITableView删除按钮标题

无论如何,是否每个间隔都重新启动Azure经典云服务角色?

UITableView在滑动以删除但不是整个UI后冻结

自定义JUnit规则允许所有测试通过,无论如何

如何在 UITableView 禁用滑动删除选项

纯vi(非vim):不能在插入模式下删除行:POSIX是否需要此行为?