我想从表中完全删除isEditing红色图标,我还想重新启用行动操作功能,这似乎是重写。
目前我可以没有isEditing命令并使用滑动来获取我的行动作,但是无法重新排列图标和功能。或者我已启用isEditing并且无法滑动以执行我的操作我必须单击大量的红色按钮,但我可以让我的单元格重新排列图标...
有没有办法可以滑动行动并重新排列我的细胞?没有红色编辑图标覆盖所有内容!
问题截图:我必须让这个红色图标有重新排列的图标,并禁止用户在图2中的行动作中滑动...
目前的一些相关代码:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
let userExercise = self.fetchedResultsController.self.managedObjectContext
print("EXERCISE TO BE DELETED IS \(userExercise)")
userExercise.delete(self.fetchedResultsController.object(at: indexPath))
do {
try userExercise.save()
print("DELETE COMPLETED")
self.workoutDesignerTable.reloadData()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
let edit = UITableViewRowAction(style: .normal, title: "Edit") { (action, indexPath) in
let cell = tableView.cellForRow(at: indexPath)
self.updateExercise = self.fetchedResultsController.object(at: indexPath)
self.performSegue(withIdentifier: self.segueEditUserExerciseViewController, sender: cell)
}
edit.backgroundColor = UIColor.lightGray
return [delete, edit]
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let UserExercise = fetchedResultsController.self.managedObjectContext
UserExercise.delete(fetchedResultsController.object(at: indexPath))
do {
try UserExercise.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false
}
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath)-> Bool {
return true
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
var movableUserExercisesArray = self.fetchedResultsController.fetchedObjects
let movedObject = movableUserExercisesArray?[sourceIndexPath.row]
movableUserExercisesArray?.remove(at: sourceIndexPath.row)
movableUserExercisesArray?.insert(movedObject!, at: destinationIndexPath.row)
print("THIS WAS MOVED FROM \(sourceIndexPath.row) => TO DESINATION \(destinationIndexPath.row)")
// attempting to set index paths - doesnt work as we fetched new?
movedObject?.arrayPosition = Int64(destinationIndexPath.row)
do {
try self.managedObjectContext.save()
} catch {
fatalError("Failure to save context: \(error)")
}
}
修改
我添加了
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return .none
}
现在隐藏了红色图标,但是我仍然无法滑动以进行行动,删除红色按钮会在isEditing打开时删除任何访问它们的功能,是否可以恢复滑动访问?