Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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 选择单元格后如何移动单元格_Ios_Swift_Uitableview_Cells - Fatal编程技术网

Ios 选择单元格后如何移动单元格

Ios 选择单元格后如何移动单元格,ios,swift,uitableview,cells,Ios,Swift,Uitableview,Cells,我正在锁定方法中的解决方案 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: UIIndexPath) { } 选择一行后,它应更改颜色并移动到数组末尾,另一行应上移要下移该行,可以执行以下操作: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: UIIndexPath) { //move s

我正在锁定方法中的解决方案

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: UIIndexPath) {
}

选择一行后,它应更改颜色并移动到数组末尾,另一行应上移

要下移该行,可以执行以下操作:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: UIIndexPath) {
    //move selected cell down to last row
    tableView.moveRowAtIndexPath(indexPath, toIndexPath:NSIndexPath(forRow: tableView.numberOfRowsInSection(indexPath.section)-1, inSection: indexPath.section))
}

要更改颜色,请参见要下移行,可以执行以下操作:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: UIIndexPath) {
    //move selected cell down to last row
    tableView.moveRowAtIndexPath(indexPath, toIndexPath:NSIndexPath(forRow: tableView.numberOfRowsInSection(indexPath.section)-1, inSection: indexPath.section))
}

有关更改颜色的信息,请参见

有关数据一致性的信息,您必须分别移动表和数据源数组中的项

dataSourceArray
表示数据源数组

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

  let itemToMove = dataSourceArray[indexPath.row]
  dataSourceArray.removeAtIndex(indexPath.row)
  dataSourceArray.append(itemToMove)

  let destinationIndexPath = NSIndexPath(forRow: dataSourceArray.count - 1, inSection: indexPath.section)
  tableView.moveRowAtIndexPath(indexPath, toIndexPath:destinationIndexPath)
}

为了数据一致性,您必须分别移动表和数据源数组中的项

dataSourceArray
表示数据源数组

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

  let itemToMove = dataSourceArray[indexPath.row]
  dataSourceArray.removeAtIndex(indexPath.row)
  dataSourceArray.append(itemToMove)

  let destinationIndexPath = NSIndexPath(forRow: dataSourceArray.count - 1, inSection: indexPath.section)
  tableView.moveRowAtIndexPath(indexPath, toIndexPath:destinationIndexPath)
}

你需要在上移或下移时应用动画吗?你需要在上移或下移时应用动画吗?非常感谢,它很有效而且很简单,我从几天开始搜索解决方案:)非常感谢,它很有效而且很简单,我从几天开始搜索解决方案:)谢谢你的提示,但是,如果我的数组中有很多元素,但没有看到最后一个,请单击第一个,它将移动到数组的末尾并成为灰色背景,但是如果我向下滚动并看到最后一个元素,然后选择一个,则最后一个元素将正确向下移动,而不改变颜色。您现在知道它发生的原因了吗?显式滚动调用
cellforrowatinexpath
。如果这一行可见,您可以添加一行来重新加载它。可能是一种方法,我有点绝望地感谢您提供了tipp,但是如果我的数组中有很多元素,但没有看到最后一个元素,请单击第一个,它将移到数组的末尾并成为灰色背景,但是如果我向下滚动,看到最后一个元素,然后选择一个元素,最后一个元素正确向下移动,而不改变颜色。您现在知道它发生的原因了吗?显式滚动调用
cellforrowatinexpath
。如果这一行可见,您可以添加一行来重新加载它。也许是一种方法,我有点绝望