iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 允许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
    }
}

一切都运行正常,但我希望编辑模式只是为了重新排序.我不希望出现红色减号,但我想保持滑动动作.

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

解决方法

我相信您需要在代码中更改的唯一内容是ediTingStyleForRowATindexPath函数.如果表视图未处于编辑模式,则仅返回.delete.

这种方式滑动到删除仍然有效(不在编辑模式下),当您切换到编辑模式时,无法删除该行.

大佬总结

以上是大佬教程为你收集整理的ios – 允许UITableView重新排序,但不能在编辑模式下删除,并启用滑动删除全部内容,希望文章能够帮你解决ios – 允许UITableView重新排序,但不能在编辑模式下删除,并启用滑动删除所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。