我用滑动实现了两个动作(一个是删除)
我有一个编辑按钮来启用编辑模式(重新排序行)
为此,我实施了
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重新排序,但不能在编辑模式下删除,并启用滑动删除所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)