1

I'm locking for the solution in the method

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

After I select a Row it should change the color and move to the End of the Array, the other one should move up

Antonio K
  • 144
  • 11

2 Answers2

0

To move the row down, you can do:

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))
}

For changing the color see How to change color of UITableViewCell when selecting?

Community
  • 1
  • 1
Daniel
  • 20,420
  • 10
  • 92
  • 149
0

For data consistency you have to move the item in the table and the data source array respectively.

dataSourceArray represents the data source array

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)
}
vadian
  • 274,689
  • 30
  • 353
  • 361
  • Thank you for the tipp, but if I have a lot of elements in my array and don't see the last one, click the first, it moves to the end of the array and become gray background, but if I scroll down and see the last element and then pick one bevor the last it move down rightly without changing the color. Do you now why its happened?? – Antonio K Jan 27 '16 at 11:43
  • Scrolling recalls `cellForRowAtIndexPath` explicitly. You might add a line to reload this particular row if it's visible. – vadian Jan 27 '16 at 11:51
  • maybe an approach, I'm a little bit desperately – Antonio K Jan 27 '16 at 12:55