Chris Schlitt Chris Schlitt - 4 years ago 140
Swift Question

Swift 3 - Changing Order of Rows in Static TableView Controller

I am trying to change the order of a particular group of cells in a particular section of UITableView with static content. I am trying to do this before the view loads, but for some reason I cannot get it to work.

I have tried creating reference outlets for each of the cells and then calling tableView.moveRow by calling in tableView.indexPath(for: cell1

I have also tried giving each a tag and looping through the cells in that section and reordering with with no success.

I have tried:

// Moving the row from it's default row
self.tableView.moveRow(at: IndexPath(row: 1, section: 1), to: IndexPath(row: newRow, section: 1))

// Creating a reference outlet called cell1
self.tableView.moveRow(at: self.tableView.indexPath(for: cell1)!, to: IndexPath(row: newRow, section: 1))

// Giving the static cell a reuseidentifier in interface builder
self.tableView.dequeueReusableCell(withIdentifier: "Cell1", for: IndexPath(row: self.subwayOrder+1, section: 1))

Answer Source

Depending on what you're trying to achieve, you could possibly have success switching index paths in cellForRow by calling super's implementation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download