Reputation: 1
I have been trying to find some way to re-oder table sections by drag and drop exactly like re-ordering table rows but no success. can someone guide me where to go? I only need to re order complete section not some rows.
Upvotes: 0
Views: 269
Reputation: 285260
Simple way with the standard delegate methods
Implement tableView:moveRowAtIndexPath:toIndexPath:
data
represents the data source array containing the sections.
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let itemToMove = data[sourceIndexPath.section]
data.removeAtIndex(sourceIndexPath.section)
data.insert(itemToMove, atIndex: destinationIndexPath.section)
tableView.reloadData()
}
Set editing
of the table view to true
. The reorder symbol appears.
moveRowAtIndexPath
reorders the entire section.Upvotes: 2