我锁定了方法中的解决方案
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: UIIndexPath) {
}
在我选择一个行之后,它应该会改变颜色并移动到数组的末尾,另一个应该会向上移动
发布于 2016-01-26 09:07:50
要向下移动行,可以执行以下操作:
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))
}
有关更改颜色的信息,请参阅How to change color of UITableViewCell when selecting?
发布于 2016-01-26 09:21:18
为了保持数据的一致性,您必须分别在表和数据源数组中移动该项。
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)
}
https://stackoverflow.com/questions/35010074
复制相似问题