Skip to content

Instantly share code, notes, and snippets.

@shxl
Created January 14, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shxl/e746ab03599ffb69a0a6 to your computer and use it in GitHub Desktop.
Save shxl/e746ab03599ffb69a0a6 to your computer and use it in GitHub Desktop.
reorder interaction w/o disgusting edit stuff
class SubjectTableViewController: UITableViewController {
var data = ["dan", "blair", "serena ;);)", "(i wish i was) chuck bass", "nate", "stupid jenny", "eric looked stupid blonde"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.editing = true
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("SubjectCell", forIndexPath: indexPath)
cell.textLabel?.text = data[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return .None
}
override func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let movedObject = self.data[sourceIndexPath.row]
data.removeAtIndex(sourceIndexPath.row)
data.insert(movedObject, atIndex: destinationIndexPath.row)
NSLog("%@", "\(sourceIndexPath.row) => \(destinationIndexPath.row) \(data)")
// To check for correctness enable: self.tableView.reloadData()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment