cell的位置交换
先上代码:
/// Move Cell
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
LOG("star:\(sourceIndexPath.row) end:\(destinationIndexPath.row)")
let bk = bookmark[sourceIndexPath.row]
if sourceIndexPath.row > destinationIndexPath.row {
realm.write {
self.bookmark.insert(bk, atIndex: destinationIndexPath.row)
self.bookmark.removeAtIndex(sourceIndexPath.row + 1)
}
} else if sourceIndexPath.row < destinationIndexPath.row {
realm.write {
self.bookmark.insert(bk, atIndex: destinationIndexPath.row + 1)
self.bookmark.removeAtIndex(sourceIndexPath.row)
}
}
}