Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式设置UITableViewCell移动到底部的动画_Ios_Swift_Tableview - Fatal编程技术网

Ios 以编程方式设置UITableViewCell移动到底部的动画

Ios 以编程方式设置UITableViewCell移动到底部的动画,ios,swift,tableview,Ios,Swift,Tableview,我在同一个区域有一组单元格。当我按下其中一个单元格上的按钮时,我希望它移动到底部,并带有动画,在其他单元格上移动。我想到的动画类似于在编辑模式下拖动单元格时发生的情况,但我希望在点击按钮时以编程方式完成。 对于我收集到的内容,我应该使用tableView.moveRowatineXpath,但我似乎无法正确执行: //inside the function for when the button is pressed let cell = sender.superview?.supervie

我在同一个区域有一组单元格。当我按下其中一个单元格上的按钮时,我希望它移动到底部,并带有动画,在其他单元格上移动。我想到的动画类似于在编辑模式下拖动单元格时发生的情况,但我希望在点击按钮时以编程方式完成。 对于我收集到的内容,我应该使用
tableView.moveRowatineXpath
,但我似乎无法正确执行:

 //inside the function for when the button is pressed
 let cell = sender.superview?.superview?.superview as! MainTableViewCell
 let indexPath = tableView.indexPathForCell(cell)
 let goal = goals[(indexPath?.row)!]

 goals.removeAtIndex((indexPath?.row)!)
 goals.append(goal)

 tableView.beginUpdates()
 self.tableView.moveRowAtIndexPath(indexPath!, toIndexPath: indexPaths.last!)
 tableView.endUpdates()

 tableView.reloadData()
在此之后,函数将禁用触发函数本身的按钮。我注意到发生的情况是,不仅我想移动的单元格被禁用,而且该部分中的最后一个单元格也被禁用。如果最后一个单元格已被禁用,则最后一个单元格之前的单元格将被禁用,依此类推。 任何帮助都将不胜感激


编辑:我还调用了
canMoveRowAtIndexPath
并返回true。

如果调用
tableView.reloadData()
您将失去动画效果。您应该能够移动单元格,然后更新数据源(目标数组),以反映项目的新顺序。对于单个更新,您也不需要调用
tableView.beginUpdates()
tableView.endUpdates()
。您可以使用这些调用批处理多个更新(插入、删除、移动等)

我创建了一个简单的测试项目来验证,使用简单的字符串作为数据项,动画效果如预期的那样工作。参见此处要点:

我这样做:

UIView.transition(with: tableView, duration: 0.35, options: .transitionCrossDissolve, animations: { self.tableView.moveRow(at: indexPath, to: indexPath.last) })
要移动到开头,请执行以下操作:

UIView.transition(with: tableView, duration: 0.35, options: .transitionCrossDissolve, animations: { self.tableView.moveRow(at: indexPath, to: [0,0]) })

从MoveRowatineXpath获得的动画不符合您的需要?还是动画不起作用?@bbjay动画不起作用。关于这种“奇怪”的按钮行为,我永远不会依赖于在同时操作表行时直接修改
UITableViewCell
的视图,尤其是在后面跟着
重新加载数据时。是否启用该按钮应作为模型的一部分保存,并用于在
表格视图:cellForRowAtIndexPath:
中正确配置单元格。
UIView.transition(with: tableView, duration: 0.35, options: .transitionCrossDissolve, animations: { self.tableView.moveRow(at: indexPath, to: [0,0]) })