Created
January 14, 2016 21:51
-
-
Save shxl/e746ab03599ffb69a0a6 to your computer and use it in GitHub Desktop.
reorder interaction w/o disgusting edit stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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